Nginx
2015-08-12 14:08
525 查看
安装
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
user 用户 组
//进程数,一般设置为核数
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;
}
}
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
user 用户 组
//进程数,一般设置为核数
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模块开发(2)————下载文件
- Nginx模块开发(1)————类helloworld
- Nginx编译与安装
- windows+nginx+php配置
- LNMP--Nginx代理详解
- Nginx服务器不支持PATH_INFO的问题及解决办法
- LNMP--Nginx禁止指定user_agent
- 如何收集 NGINX 指标(第二篇)
- 如何监控 Nginx(第一篇)
- LNMP--Nginx配置防盗链
- 让nginx支持PHP
- 利用nginx做负载均衡
- LNMP--Nginx的日志切割
- J2ee获取通过Nginx代理的客户端真实IP地址
- LNMP--Nginx不记录指定文件日志
- nginx与Apache的优缺点
- nginx服务器去掉url中的index.php 和 配置path_info
- nginx rewrite小问题
- 使用elasticsearch与kibana来分析nginx日志小结
- nginx cache 配置