同时监听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; #将IPV4+IPV6的8057端口请求反向代理至tomcat8080接口地址 server{ listen 8057; listen [::]:8057 ipv6only=on; server_name tomcat_server; location /interfaceUri { #proxy_pass http://[fe80::5154:ff:fabc:d8ae]:8080/northbound/query; proxy_pass http://101.96.15.40:8080/northbound/query; } } #IPV4+IPV6监听8077端口 定期查询html页面生成日志保证cache服务器心跳 server{ listen 8077; listen [::]:8077 ipv6only=on; server_name X-Cache; location / { root /opt/server/department/nginx/html; } } include /opt/server/department/nginx/conf/conf.d/*.conf; }
同时监听IPV4+IPV6的8057端口
listen 8057;
listen [::]:8057 ipv6only=on;
这样配置可以同时监听IPV4+IPV6,测试过没问题
同时监听IPV4+IPV6的8057端口
listen [::]:8057;
这样配置可能存在ipv4不通的情况,暂时没找到原因
双栈虚拟域名配置示例
server { listen 30050; listen [::]:30050 ipv6only=on; server_name www.test.cn; access_log /var/log/nginx/access-30050-www.log; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/www/html; } server { listen 30050; listen [::]:30050; server_name dev.test.cn; access_log /var/log/nginx/access-30050-dev.log; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/dev/html; } server { listen 30050; listen [::]:30050; server_name ops.test.cn; access_log /var/log/nginx/access-30050-ops.log; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/ops/html; } }
ipv6only=on只能添加一次,否则nginx会报错端口重复
如上配置即可支持同一Nginx下单端口3个域名
原文链接:https://blog.csdn.net/Skywin88/article/details/84747066
© 版权声明
声明📢本站内容均来自互联网,归原创作者所有,如有侵权必删除。
本站文章皆由CC-4.0协议发布,如无来源则为原创,转载请注明出处。
THE END