美文网首页
ngnix 一个域名配置多个项目访问

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

作者: 東玖零 | 来源:发表于2022-03-04 18:00 被阅读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

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

    相关文章

      网友评论

          本文标题:ngnix 一个域名配置多个项目访问

          本文链接:https://www.haomeiwen.com/subject/qtemrrtx.html