vue代理访问nginx server_name

时间:2018-02-01 17:04:11

标签: nginx proxy vue.js

我的代码如下:

  1. webpack.dev.config.js

    devServer: {
        port: config.port,
        proxy: config.proxy
    }
    
  2. config.js

    module.exports = {
        port: 8099,
        proxy: {
            "/api/v1/*": "http://192.168.1.11", //it is proxy by nginx, not works
            // "/api/v1/*": "http://192.168.1.11:8033", //access tomcat directly, it works
        }
    };
    
  3. nginx.conf

    upstream tomcat {
        server 127.0.0.1:8033 weight=10 max_fails=2 fail_timeout=30s;
    }
    server {
        listen                   80;
        server_name     192.168.1.11;
        location / {
            proxy_next_upstream     http_500 http_502 http_503 http_504 error timeout invalid_header;
            proxy_pass              http://tomcat;
            expires                 0;
        }
        location /logs/ {
            autoindex       off;
            deny all;
        }
    }
    
  4. 然后我启动我的前端服务器,并测试,我得到如下的请求标头:

        POST /api/v1/login HTTP/1.1
        Host: localhost:8099
        Connection: keep-alive
        Content-Length: 25
        Accept: application/json, text/plain, */*
        Origin: http://localhost:8099
        User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
        Content-Type: application/x-www-form-urlencoded
        Referer: http://localhost:8099/
        Accept-Encoding: gzip, deflate, br
        Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7
    
    查看请求标头,“Host”是“localhost:8099”,它不是我的nginx代理,所以它无法访问我的nginx代理服务器;我的nginx日志也没有访问记录,我想知道我可以解决它吗?非常感谢!! 顺便说一句,我的英语很差,如果你不能理解我,我很抱歉。

0 个答案:

没有答案