Nginx
来源:互联网 发布:java如何实现多线程 编辑:程序博客网 时间:2024/06/10 08:37
安装
tar -zxvf nginx.tar.gz
cd nginx
./configure --prefix=/opt --user=nginx --group=nginx
make
make install
配置
/sbin/nginx -t -c nginx.conf 测试配置文件是否正确
location实现反向代理,upstream实现负载均衡nginx.conf
//进程数,一般设置为核数
worker_processes 4;
events{
use epoll;//网络IO模型
worker_connections 51200;//最大连接数
}
//错误日志,日志等级 crit(关键)
error_log /opt/nginx/logs/error.log [debug|info|notice|warn|error|crit]
//进程号文件,里面放一个当前进程号
pid /opt/nginx/logs/nginx.pid
http
{
//压缩传输
gzip on;
gzip text/css application/xml application/x-javascript;
//设定 expires 和 Cache-Control,也可以放在 server、location中
expires [time|epoch|max|off]
//反向代理的上游
upstream tomcat_server{
ip_hash;//根据源IP定位到目标IP
server 192.168.8.45:8080 weight=4 max_fails=2 fail_timeout=30s;//权重、最大失败次数、失败超时时间
server 192.168.8.46:8080 weight=4 max_fails=2 fail_timeout=30s down;//down 暂时不用
}
}
//虚拟机主机,可配置多个
server
{
//监听IP
listen 192.168.8.43:80;
server_name 192.168.8.43;
//访问日志存放路径,日志格式 combined,不打日志 off,buffer 缓存大小,不立即打印
access_log /opt/nginx/logs/server1.access.log combined buffer=32k
ssl on;
ssl_certificate 证书文件;
ssl_certificate_key 私钥文件;
location /
{
//首页
index index.html index.htm
//静态文件根目录
root /opt/nginx/html/server1;
}
//匹配图片~起始,$结束
location ~* \.(gif|jpg|png)$ {
expires 30d;
}
//将jsp请求映射到tomcat服务器
location ~\.(jsp|jspx|do)?${
proxy_set_header Host $host;
//把来访IP写到请求头里面
proxy_set_header X-remote_addr $remote_addr;
proxy_pass http://tomcat_server;
//将请求发给下一台机器的情况
proxy_next_upstream http_502 http_504 error timeout invalid_header;
}
}
- nginx
- Nginx
- Nginx
- Nginx
- Nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- Nginx
- nginx
- nginx
- nginx
- nginx
- linux设备驱动归纳总结(三):2.字符型设备的操作open、close、read、write
- JS学习第七天----语句
- Discovery(3)
- 利用SecureCRT上传、下载文件(使用sz与rz命令),超实用!
- iOS UI10_带分区的省市区
- Nginx
- Volley实现自定义的网络请求Implementing a Custom Request
- PHP_PHP开发框架-Phalcon
- Android生命周期
- SVN 版本冲突解决
- 黑马程序员--------------java基础----------------- 图形化界面
- 怎么知道Java class文件JDK编译的版本号
- iOS开发 - 苹果开发者账号那些事儿(二)
- linux 变量01