I have summarized 3 methods to deploy multiple front-end projects on one server using nginx.
Before we start, let's take a look at the default configuration file for nginx installation: /etc/nginx/nginx.conf file You can see in the figure: Now that the introduction is over, let’s talk about the most commonly used method that many companies use online. Domain name based configurationBased on domain name configuration, the premise is that domain name resolution has been configured first. For example, you bought a domain name: www.fly.com. Then you configured two of its second-level domain names in the background: a.fly.com and b.fly.com. The configuration files are as follows: Configure the configuration file of a.fly.com: vim /usr/nginx/modules/a.conf server { listen 80; server_name a.fly.com; location / { root /data/web-a/dist; index index.html; } } Configure the configuration file of b.fly.com: vim /usr/nginx/modules/b.conf server { listen 80; server_name b.fly.com; location / { root /data/web-b/dist; index index.html; } } The advantage of this method is that the host only needs to open port 80. Then you can access it by directly accessing the second-level domain name. Port-based configurationThe configuration files are as follows: Configure the configuration file of a.fly.com: vim /usr/nginx/modules/a.conf server { listen 8000; location / { root /data/web-a/dist; index index.html; } } # nginx port 80 configuration (listening to the secondary domain name a) server { listen 80; server_name a.fly.com; location / { proxy_pass http://localhost:8000; #Forward} } Configure the configuration file of b.fly.com: vim /usr/nginx/modules/b.conf server { listen 8001; location / { root /data/web-b/dist; index index.html; } } # nginx port 80 configuration (listening to the b secondary domain name) server { listen 80; server_name b.fly.com; location / { proxy_pass http://localhost:8001; #Forward} } As you can see, this method starts a total of 4 servers, and the configuration is far less simple than the first one, so it is not recommended. Based on location configurationThe configuration files are as follows: Configure the configuration file of a.fly.com: vim /usr/nginx/modules/ab.conf server { listen 80; location / { root /data/web-a/dist; index index.html; } location /web-b { alias /data/web-b/dist; index index.html; } } Note: When configured in this way, the location / directory is the root, and the others must use aliases. As you can see, the advantage of this method is that we only have one server, and we do not need to configure a secondary domain name. And For react configuration, please refer to: https://blog.csdn.net/mollerlala/article/details/96427751 For vue configuration, please refer to: https://blog.csdn.net/weixin_33868027/article/details/92139392 This concludes this article about several methods of deploying multiple front-end projects with nginx. For more information about deploying multiple front-end projects with 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:
|
<<: MySQL optimization: how to write high-quality SQL statements
>>: A must-read career plan for web design practitioners
<br />Structure and hierarchy reduce complex...
Problem Reproduction When using HTML for editing,...
@Font-face basic introduction: @font-face is a CSS...
[LeetCode] 185. Department Top Three Salaries The...
Table of contents 1. Find the mirror 2. Download ...
Preface Workbench is installed on one computer, a...
Preface: During database operation and maintenanc...
The main symptom of the conflict is that the FLASH...
1. Installation Instructions Compared with local ...
When using Flex layout, you will find that when a...
Server placement It is recommended to use cloud s...
1. InnoDB locking mechanism The InnoDB storage en...
Table of contents 1. Index Type 1. B+ Tree 2. Wha...
There are three ways to start a springboot projec...
The first thing to do is to pick a good browser. ...