nginx 转发请求到指定网站

实现目的:

如果本地电脑访问某个网站比较慢,但是通过服务器访问就比较快,可以考虑使用nginx转发请求的方式.

server {
        listen 5555 default_server; # 指定你的服务器要监听的端口
        listen [::]:5555 default_server; # 指定监听端口
        server_name _;

        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;

        # rewrite ^(.*)$ https://www.odoo.com/;
            location / {
                proxy_pass https://www.odoo.com/; # 设置要转发的网址.
                proxy_set_header X-Forwarded-Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                client_max_body_size 20m;

  }

}

相关推荐