How does nginx configure multiple front-end projects?

10-30-2023

Recently, a server needs to configure multiple front-end projects. Of course, nginx is needed to configure the front-end and back-end separation.

For a single project, modify the nginx.conf configuration file of Nginx as follows.

#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid /usr/local/nginx/logs/nginx.pid; events { worker_connections 1024; }http { server { listen 8000; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root /var/www/; #index index.html index.htm ; } location ~ /static/.*.(gif|jpg|jpeg|png|bmp|swf)$ { root /var/www/project; } location ~ /static/.*.(js|css)$ { root /var/www/project; } location = /project { root /var/www/project; index index.html index.htm ; } }}

However, there are many projects that need to be configured in nginx.conf

The project is developed based on vue cli. When packaging, you need to configure the connection address of static files such as js and css, and modify the following configuration files.

Modify it in the corresponding project according to the project name or path name.

assetsPublicPath: '/project/'-----------------------assetsPublicPath: '/project1/'

And then configure nginx.conf

user root; worker_processes 1; pid /usr/local/nginx/logs/nginx.pid; events { worker_connections 1024; }http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user

Successfully visited 192.168 ...: 8000/project/index.html192.168 ...: 8000/project1/index.html.

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us