ngnix 一个域名配置多个项目访问

2022-03-04  本文已影响0人  東玖零

为啥要一个域名配多个项目?一个项目配一个域名不好嘛?

一个项目配一个域名当然好,为了省钱和错误的以为免费的证书只能申请一个,于是就走上了一个域名配置多个项目访问的路程。

这里有两个项目:

1.官网电脑端,打包Vue前端项目文件夹:web-computer。

server {
    
    listen 443 ssl;
    ssl_certificate "/etc/pki/nginx/abc.com.pem";
    ssl_certificate_key "/etc/pki/nginx/abc.com.key";

    server_name abc.com www.abc.com;
    
    location ^~/web-computer {
        alias /root/webapps/web-computer/;
        try_files $uri $uri/ /web-computer/index.html;
        index index.html index.htm;
    }

    error_log /root/webapps/logs/www/error.log;
    access_log /root/webapps/logs/www/access.log;
}

2.官网移动端,打包Vue前端项目文件夹:web-mobile。

server {
    
    listen 443 ssl;
    ssl_certificate "/etc/pki/nginx/abc.com.pem";
    ssl_certificate_key "/etc/pki/nginx/abc.com.key";

    server_name abc.com www.abc.com;
    
    location ^~/web-mobile {
        alias /root/webapps/web-mobile/;
        try_files $uri $uri/ /web-mobile/index.html;
        index index.html index.htm;
    }

    error_log /root/webapps/logs/www/error.log;
    access_log /root/webapps/logs/www/access.log;
}

vue工程中还有一点要修改的config/index.js中assetsPublicPath的值改为对应项目的文件夹名,有两处。

移动端如图1 移动端如图2

打包后放到对应的文件夹,就可以访问https://abc.com/web-mobile

以上皆是实践得出,可能会有不正确之处。

上一篇下一篇

猜你喜欢

热点阅读