修改nginx配置,同一台服务器部署多个前端项目
修改nginx.conf
前提:
前端项目打包时,修改vue.config.js配置
module.exports = defineConfig({
publicPath: './',
......
)}
举例
- 通过前缀区分多个前端项目
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /var/lib/thci/pki/app.pem;
ssl_certificate_key /var/lib/thci/pki/app-key.pem;
proxy_set_header Remote_addr $remote_addr;
// 原本的
location / {
root /etc/nginx/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
// 新加的
// 注意得用 alias
location /访问前缀名 {
alias /etc/nginx/包名;
index index.html index.htm;
try_files $uri $uri/ /cloudspace/index.html;
autoindex off;
}
- 通过端口号区分不同项目
server {
listen 998 ssl; //访问端口号
server_name localhost;
ssl_certificate /var/lib/thci/pki/app.pem;
ssl_certificate_key /var/lib/thci/pki/app-key.pem;
proxy_set_header Remote_addr $remote_addr;
location / {
root /etc/nginx/报名;
index index.html index.htm;
...............