nuxt项目部署后的nginx代理配置

关于nuxt部署参阅https://blog.csdn.net/weixin_36185028/article/details/106335681

1,安装nginx

2,配置nginx

在nginx中配置能在不同的设备自动定向到h5或pc页面

假设网站域名为xxx.com,nuxt启动后pm2的list中的pc端进程为xxxpc,package.json中端口运行端口为3011;h5端进程为xxxh5,package.json中端口运行端口为3012;网站访问端口为80

cd /etc/nginx/conf.d

新建xxx.conf

server {
        listen      801;
        server_name xxxpc;
        location / {
                proxy_pass       http://127.0.0.1:3011/;
                proxy_redirect default;
                proxy_http_version 1.1;
                proxy_set_header Host      $host;
                proxy_set_header X-Real-IP $remote_addr;
        }
}
server {
        listen      802;
        server_name xxxh5;
        location / {
                proxy_pass       http://127.0.0.1:3012/;
                proxy_redirect default;
                proxy_http_version 1.1;
                proxy_set_header Host      $host;
                proxy_set_header X-Real-IP $remote_addr;
        }
}

server {
        listen      80;
        server_name xxx.com;
        location / {
                proxy_set_header X-Real-IP $remote_addr;        
                proxy_pass  http://xxxpx:801/;

                if ($http_user_agent ~ "(MIDP)|(WAP)|(UP.Browser)|(Smartphone)|(Obigo)|(Mobile)|(AU.Browser)|(wxd.Mms)|(WxdB.Browser)|(CLDC)|(UP.Link)|(KM.Browser)|(UCWEB)|(SEMC\-Browser)|(Mini)|(Symbian)|(Palm)|(Nokia)|(Panasonic)|(MOT\-)|(SonyEricsson)|(NEC\-)|(Alcatel)|(Ericsson)|(BENQ)|(BenQ)|(Amoisonic)|(Amoi\-)|(Capitel)|(PHILIPS)|(SAMSUNG)|(Lenovo)|(Mitsu)|(Motorola)|(SHARP)|(WAPPER)|(LG\-)|(LG/)|(EG900)|(CECT)|(Compal)|(kejian)|(Bird)|(BIRD)|(G900/V1.0)|(Arima)|(CTL)|(TDG)|(Daxian)|(DAXIAN)|(DBTEL)|(Eastcom)|(EASTCOM)|(PANTECH)|(Dopod)|(Haier)|(HAIER)|(KONKA)|(KEJIAN)|(LENOVO)|(Soutec)|(SOUTEC)|(SAGEM)|(SEC\-)|(SED\-)|(EMOL\-)|(INNO55)|(ZTE)|(iPhone)|(Android)|(Windows CE)|(Wget)|(Java)|(curl)|(Opera)") {
                        proxy_pass  http://xxxh5:802;
                }
        }
	location ^~ /static/ {
                alias /home/webapp/xxx/upload/;
                autoindex on;
        }
}

3,配置hosts

vim /etc/hosts

添加:

127.0.0.1   xxxpc
127.0.0.1   xxxh5

4,重启nginx

sudo systemctl restart nginx

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页