nuxt项目部署后的nginx代理配置
Posted 骑着代马去流浪
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于nuxt项目部署后的nginx代理配置的主要内容,如果未能解决你的问题,请参考以下文章