文件目录结构
nginx版本:1.9.7
这里主要介绍配置文件目录conf
目录:/usr/local/nginx/conf
包含配置文件:nginx.conf
backends/demo.cn.conf
sites/demo.cn.conf
具体文件配置如下:
nginx.conf:
#user nobody;
worker_processes 1;
#nginx异常日志
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
fastcgi_intercept_errors on;
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for""::::" "$Host"';
#nginx接收请求的日志
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
#keepalive_timeout 65;
#include mime.types;
#default_type application/octet-stream;
charset utf-8 ;
server_names_hash_bucket_size 128;
client_header_buffer_size 2k;
large_client_header_buffers 4 4k;
client_max_body_size 8m;
#sendfile on;
tcp_nopush on;
keepalive_timeout 600s;
#fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2
#keys_zone=TEST:10m
#inactive=5m;
fastcgi_connect_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
fastcgi_buffer_size 10m;
fastcgi_buffers 8 10m;
fastcgi_busy_buffers_size 10m;
fastcgi_temp_file_write_size 10m;
#fastcgi_cache TEST;
fastcgi_cache_valid 200 302 1h;
fastcgi_cache_valid 301 1d;
fastcgi_cache_valid any 1m;
fastcgi_cache_min_uses 1;
fastcgi_cache_use_stale error timeout invalid_header http_500;
open_file_cache max=204800 inactive=20s;
open_file_cache_min_uses 1;
open_file_cache_valid 30s;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
#gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#gzip on;
#负载分发具体配置文件
include backends/*; 数据转发配置
include sites/*;
}
数据转发配置文件
backends/demo.cn.conf
#mvc为tomcat下系统工程名字
upstream mvc{
server 192.168.3.51:8088; 部署系统的两台服务器之一(tomcat)
server 192.168.3.51:8089; 部署系统的两台服务器之一(tomcat)
}
正文处理配置文件
sites/demo.cn.conf
server{
listen 80; 监听端口
server_name demo.cn; 请求主域名
location ~ /mvc/(.*){ 请求路径中带有 /mvc/的处理
proxy_pass http://mvc;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
本次demo的应用名称为mvc,通过nginx进行访问的路径为 demo.cn/mvc/
在局域网访问时 需要配置host 127.0.0.1 demo.cn
至此,demo全部配置完成,扩展使用nginx的其他功能需阅读nginx官方文档