There are two ways to configure multiple projects under the same domain name using Nginx:
1. nginx is distributed to different projects according to different directories: server { listen 80; server_name example.com; location ^~ /project1 { proxy_pass http://localhost:8081; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ^~ /project2 { proxy_pass http://localhost:8082; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } Three projects are configured here:
2. Enable the second-level domain name, and assign different second-level domain names to different projects Note: Many students say it is invalid because you must first add an A record to the secondary domain name to the host. The same domain name can add N secondary domain names to the same host. server { listen 80; server_name example.com; location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } project1 server { listen 80; server_name project1.example.com; location / { proxy_pass http://localhost:8081; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } project2 server { listen 80; server_name project2.example.com; location / { proxy_pass http://localhost:8082; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } Note: These three projects belong to different domain names, and there will be cross-domain issues when accessing projects via http. This is the end of this article about how to configure multiple projects with the same domain name in Nginx. For more information about configuring multiple projects with the same domain name in Nginx, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Example of using CSS3 to customize the style of input multiple-select box
>>: Collapsed table row element bug
Text hiding code, hide a certain text in HTML Copy...
When installing a virtual machine, a prompt appea...
Table of contents 1. Simple page example 2.uni-ap...
After half an hour of trying to pull the MySQL im...
CSS Selectors Setting style on the html tag can s...
Here are some points to note when registering Tom...
CentOS 8 is now available! CentOS 8 and RedHat En...
We are in an era of rapid development of mobile In...
<br />In order to clearly distinguish the ta...
1. Demand The base has 300 new servers, and needs...
In the past, when I needed the border length to b...
This article shares the specific code for JavaScr...
The loading speed of a web page is an important in...
The DATE_ADD() function adds a specified time int...
Table of contents Business scenario: Effect demon...