nginx proxy subdomains to other addresses and ports

33,599
server {
    listen 80;
    server_name admin.domain.com;
    location / {
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:3434;
        proxy_redirect off;
    }
}
server {
    listen 80;
    server_name user.domain.com;
    location / {
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:3435;
        proxy_redirect off;
    }
}
server {
    listen 80;
    server_name vendor.domain.com;
    location / {
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:3436;
        proxy_redirect off;
    }
}   
Share:
33,599

Related videos on Youtube

Beto Neto
Author by

Beto Neto

Updated on September 18, 2022

Comments

  • Beto Neto
    Beto Neto over 1 year

    I'm newbie with nginx, but I need to create some proxy rules based on the subdomain to redirect to another IP and Port.

    This is my case:

    My domain.com has IP y.y.y.y and accepts requests on port 80
    My subdomains are:
    - admin.domain.com -> I need to proxy to x.x.x.x:3434
    - user.domain.com -> I need to proxy tox.x.x.x:3435
    - vendor.domain.com -> I need to proxy to x.x.x.x:3436
    

    All subdomains are mapped to the y.y.y.y but in nginx I need to proxy to x.x.x.x:ZZZ (ZZZ is the specific port of the other services).

    I was trying this example but without success: https://rainbow-six3.com/plesknginx/

    Someone can provide an sample how to configure this on nginx?

    • Admin
      Admin almost 6 years
      If that works, it should be an answer, not a question.
  • jonincanada
    jonincanada about 4 years
    For nginx: vi /etc/nginx/sites-enabled/myproject && sudo systemctl restart nginx