Home  >  Q&A  >  body text

nginx port 80 reverse proxy multiple domain names, how to hide the port?

I use docker to deploy two projects, and nginx is used for port 80 proxy forwarding.

[root@ip-172-31-9-233 conf.d]# docker ps -a
CONTAINER ID        IMAGE                                      COMMAND                  CREATED             STATUS              PORTS                    NAMES
83b7d2ff1541        wordpress:4.5                              "/entrypoint.sh apach"   17 hours ago        Up 4 seconds        0.0.0.0:8081->80/tcp     worldpress
6810f3412fde        mysql:5.6                                  "docker-entrypoint.sh"   17 hours ago        Up 17 hours         3306/tcp                 mysql_wp
f0e77b44e9b7        fanne/flask_blog_mogodb_migrate:20160722   "/bin/bash"              13 days ago         Up 13 days          0.0.0.0:9003->9003/tcp   flask_blog_mongodb

nginx configuration information
Main configuration file

[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_type        application/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 project configuration file

[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;
                }
        }
}

When I access the first domain name, it is normal and the port content does not appear


But when accessing the second domain name, the port will appear:


will jump out the port information by itself.

Why is this?

ringa_leeringa_lee2713 days ago892

reply all(2)I'll reply

  • 黄舟

    黄舟2017-05-16 17:17:32

    Clear your browser history, this is what happens to my chrome anyway.

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 17:17:32

    The default port is 8080, so it can be hidden. It seems that other ports need to be added

    reply
    0
  • Cancelreply