uni-app调试模式使用外网域名nginx映射到本地调试解决u

2021-12-04  本文已影响0人  yichen_china

VUE内网开发,外网测试
很多公司开发环境建在内网,需要通过外网进行测试,网络跟踪工具总是提示如下错误:
GET http://本地IP/sockjs-node/info?t=一组随机数
这个错误不太重要,但是挺不爽的,要解决这个问题,可以在src/manifest.json文件中添加配置

"h5": {
        "devServer": {
            "public": "测试服务器外网IP或域名"
        }
    }

如果需要通过nginx进行代理,可以使用如下参数:

server
{
    server_name 你的域名.com;

    location /
    {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_read_timeout 360s;
        proxy_redirect off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;

        add_header X-Cache $upstream_cache_status;

        #Set Nginx Cache
        add_header Cache-Control no-cache;
        expires 12h;
    }

    location /sockjs-node
    {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_read_timeout 360s;
        proxy_redirect off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;

        add_header X-Cache $upstream_cache_status;

        #Set Nginx Cache
        add_header Cache-Control no-cache;
        expires 12h;
    }

    location /__webpack_dev_server__
    {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_read_timeout 360s;
        proxy_redirect off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;

        add_header X-Cache $upstream_cache_status;

        #Set Nginx Cache
        add_header Cache-Control no-cache;
        expires 12h;
    }
    # PROXY CRMEB END #

}

uni-app 如何修改默认端口

uni-app 默认端口为 8080,与 tomcat 的默认端口冲突。

解决方案一:不推荐
先启动 tomcat,再启动 uni-app 端口会自动修改为 8081 。

解决方案二:
打开项目—>打开 manifest.json 文件,选择h5配置,设置端口就可以了。

上一篇下一篇

猜你喜欢

热点阅读