您的位置:首页技术文章
文章详情页

nginx 80端口反向代理多个域名,怎样隐藏端口的?

【字号: 日期:2024-06-22 17:03:00浏览:112作者:猪猪

问题描述

我用docker部署两个项目,前面用nginx进行80端口代理转发。

[root@ip-172-31-9-233 conf.d]# docker ps -aCONTAINER IDIMAGE COMMAND CREATED STATUS PORTS NAMES83b7d2ff1541wordpress:4.5 '/entrypoint.sh apach' 17 hours agoUp 4 seconds0.0.0.0:8081->80/tcp worldpress6810f3412fdemysql:5.6 'docker-entrypoint.sh' 17 hours agoUp 17 hours 3306/tcp mysql_wpf0e77b44e9b7fanne/flask_blog_mogodb_migrate:20160722 '/bin/bash' 13 days ago Up 13 days 0.0.0.0:9003->9003/tcp flask_blog_mongodb

nginx配置信息主配置文件

[root@ip-172-31-9-233 nginx]# cat nginx.conf# For more information on configuration, see:# * Official English Documentation: http://nginx.org/en/docs/# * Official Russian Documentation: http://nginx.org/ru/docs/user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;events { worker_connections 1024;}http { 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 /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_typeapplication/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server {#listen 80 default_server;#listen [::]:80 default_server;#server_name _;#root /usr/share/nginx/html;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;location / {}error_page 404 /404.html; location = /40x.html {}error_page 500 502 503 504 /50x.html; location = /50x.html {} }}

include的项目配置文件

[root@ip-172-31-9-233 nginx]# cat conf.d/flask_blog_mongodb.conf server {listen 80; server_name www.suohi.cc; location / {proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;proxy_set_header Host $http_host;proxy_redirect off;if (!-f $request_filename) {proxy_pass http://127.0.0.1:9003; break;}}}

[root@ip-172-31-9-233 nginx]# cat conf.d/myopsdev.conf server {listen 80; server_name www.myopsdev.cc; location / {proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;proxy_set_header Host $http_host;proxy_redirect off;if (!-f $request_filename) {proxy_pass http://127.0.0.1:8081; break;}}}

当我访问第一个域名的时候就正常,不会出现端口内容

nginx 80端口反向代理多个域名,怎样隐藏端口的?但访问第二个域名的时候就会出现端口:

nginx 80端口反向代理多个域名,怎样隐藏端口的?会自己跳转出端口信息。

这是为咋啊的。

问题解答

回答1:

把你浏览器的历史记录清除掉,反正我的chrome会这样。

回答2:

默认都是8080端口的所以可以隐藏,其他的端口貌似都得加上吧