How to send request to proxy pass url based on server name in nginx

July 23, 2017 9k views
Nginx CentOS

i configure ngnix proxy with ip and use it ip . its working perfect
but when i try to use in name server then its not working
after lot of searching i am finding something but same issue

Problem is i want to use like it

ns1.domainname.com     >>   ngnix proxy Ip
ns2.domainname.com     >>   ngin proxy ip

here is my configure which i use to set ip.. Please give me configure which i use and set name servers

## Basic reverse proxy server ##
## HTTP backend for www.example.com ##
upstream httpweb  {
      server 5.135.175.213:80; # cPanel server
}

## Start www.example.com ##
server {
    listen       185.144.31.177:80;
    server_name  www.example.com;

    access_log  /var/log/nginx/log/www.example.access.log  main;
    error_log  /var/log/nginx/log/www.example.error.log;
    root   /usr/share/nginx/html;
    index  index.html index.htm;

    ## send request back to apache1 ##
    location / {
     proxy_pass  http://httpweb;
     proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
     proxy_redirect off;
     proxy_buffering off;
     proxy_set_header        Host            $host;
     proxy_set_header        X-Real-IP       $remote_addr;
     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
   }
}
1 Answer

Hi @SAIMRAZA786

This makes no sense:

ns1.domainname.com     >>   ngnix proxy Ip
ns2.domainname.com     >>   ngin proxy ip

What are you trying to do? Please explain from start to end, without any configurations, just in words.

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!