search

Home  >  Q&A  >  body text

How does nginx map subdomain names?

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?

PHPzPHPz2744 days ago759

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-05-16 17:24:11

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

    reply
    0
  • Cancelreply