Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx转发配置 #24

Open
ichengzi opened this issue Aug 24, 2020 · 0 comments
Open

nginx转发配置 #24

ichengzi opened this issue Aug 24, 2020 · 0 comments

Comments

@ichengzi
Copy link
Owner

ichengzi commented Aug 24, 2020

nginx 转发配置

server {
    listen       1024;
    #server_name  localhost; 正向代理不要设置server_name
    resolver 114.114.114.114 valid=600s; #指定DNS服务器IP地址
    proxy_connect_timeout 5s;
    proxy_read_timeout 150s; 
    proxy_send_timeout 150s; 
    #规则1, 正向代理
    location / {
        proxy_pass http://$host$request_uri;  #设定代理服务器的协议和地址
    }
    #规则2
    location /api/ {
        proxy_pass http://www.demo.com/api/;
    }
}

假设 server ip: 10.10.0.10
// 无代理时的请求,remote-address由dns解析得到
GET http://www.demo.com/api/product/list 
HOST www.demo.com
Remote-Address 112.80.248.76:80

// 请求时添加了proxy,会走到规则2【推荐】
GET http://www.demo.com/api/product/list 
HOST www.demo.com
Remote-Address 10.10.0.10:80

// 请求时直接替换了URL的域名, 会走到规则2【不推荐】
GET http://10.10.0.10/api/product/list 
HOST 10.10.0.10
Remote-Address 10.10.0.10:80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant