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
世界只因有你2017-05-16 17:19:48
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. . . :)
某草草2017-05-16 17:19:48
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
,在http
module 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
,当然文件名a
,b
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_name
That’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.
巴扎黑2017-05-16 17:19:48
The domain name points to the same IP and is equipped with a corresponding virtual host