1. 程式人生 > >Nginx同時監聽IPV6+IPV4,實現正向和反向

Nginx同時監聽IPV6+IPV4,實現正向和反向

nginx.conf 配置如下

user  root;
worker_processes  8;
#error_log  /opt/server/department/nginx/logs/error.log warn;
error_log  /opt/server/department/nginx/logs/error.log info;
pid        /var/run/nginx.pid;


events {
    worker_connections  2048;
}


http {
    include       /opt/server/department/nginx/conf/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"';

    access_log  /opt/server/department/nginx/logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;
    #X-Forwarded-For:簡稱XFF頭,它代表客戶端---HTTP的請求端真實的IP
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    #隱藏NGINX版本資訊
    server_tokens off;
    #gzip  on;

    lua_shared_dict FORWARD 1m;
    #init_by_lua_file  /opt/server/department/nginx/lualib/init.lua;
	
	#將IPV4+IPV6的8057埠請求反向代理至tomcat8080介面地址
	server{
      listen       8057;
      listen    [::]:8068 ipv6only=on;
      server_name  tomcat_server;
      location /interfaceUri {
	#proxy_pass http://[fe80::5154:ff:fabc:d8ae]:8080/northbound/query;        
	proxy_pass http://10.96.155.40:8080/northbound/query;
      }
  		 }	
    
    #IPV4+IPV6監聽8077埠 定期查詢html頁面生成日誌保證cache伺服器心跳
    server{
      listen       8077;
      listen       [::]:8098 ipv6only=on;
      server_name X-Cache;
      location / {
        root /opt/server/department/nginx/html;
      }
    }
    include /opt/server/department/nginx/conf/conf.d/*.conf;
}