How does nginx map subdomain names?
PHPz
PHPz 2017-05-16 17:22:11
0
1
773

I currently run several web services on a host. Currently, they are distinguished by ports. I want to provide service addresses to the outside world through subdomain names.

I made the following configuration in nginx.conf of nginx:

    server {
        listen       80;
        server_name  abc.xxx.com;
        
        location / {
                  proxy_pass http://127.0.0.1:84;
                  proxy_set_header Host $host;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                 # proxy_redirect off;
        }

Want to access the local service "http://127.0.0.1:84" through port 80 of the subdomain "abc.xxx.com"?
But it seems that only by accessing "abc.xxx.com" Access the current IP address and default port 80.

Advice: How to use nginx for subdomain name and port mapping?

PHPz
PHPz

学习是最好的投资!

reply all(1)
巴扎黑

Just configure a few more servers at the same level as the server. You can set the server_name domain name and listening port as needed

server {
    listen       80;
    server_name  abc.xxx.com;
    
    location / {
          proxy_pass http://127.0.0.1:84;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          # proxy_redirect off;
    }
}

server {
    listen       84;
    server_name  xyz.xxx.com;
    
    location / {
        # another config
    }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template