Reverse proxy - how to configure nginx with the same IP, multiple domain names, and different ports?
阿神
阿神 2017-05-16 17:17:48
0
4
857

That is, I have a domain name ABC.com
One server and two website applications
The two website applications are hung on different ports
I have set up two domain names, A.ABC.com, B.ABC.com
Accessing A.ABC.com and B.ABC.com can point to these two applications.
How to configure

阿神
阿神

闭关修行中......

reply all(4)
世界只因有你

Similar to this

server { 
listen       80; 
server_name  A.ABC.com; 
location / { 
proxy_pass http://localhost:1234; 
proxy_set_header   Host    $host; 
proxy_set_header   X-Real-IP   $remote_addr; 
proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for; 
    } 
} 

Another one:

server { 
listen       80; 
server_name  B.ABC.com; 
location / { 
proxy_pass http://localhost:4321; 
proxy_set_header   Host    $host; 
proxy_set_header   X-Real-IP   $remote_addr; 
proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for; 
    } 
} 

In this way, the two requests can be forwarded to the corresponding local program ports. . . :)

某草草

You need to configure the virtual host so that Nginx listens to port 80 of different domain names and then forwards it to the actual port of the respective application

First, you need to edit the /etc/nginx/nginx.conf,在httpmodule to introduce other configuration files:

include /etc/nginx/conf.d/*.conf;

This way you can set up each virtual host individually in a /etc/nginx/conf.d folder.

Then create new files in the above folders /etc/nginx/conf.d/a.conf/etc/nginx/conf.d/b.conf,当然文件名ab It’s up to you.

server {
    listen       80;
    server_name  a.abc.com;

    access_log /data/node/log/host.access.log  main;

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-Ip $remote_addr;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://127.0.0.1:<YOUR PORT>/;
        proxy_redirect off;
    }
}

Yesb.abc.com的应用只需要修改上面的server_nameThat’s it.

In this way, each request to access http://a.abc.com will be forwarded to the corresponding port and processed by the respective application.

巴扎黑

The domain name points to the same IP and is equipped with a corresponding virtual host

某草草

You can use Nginx’s reverse proxy

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!