nginx正向代理如何优化?

发布于 2021-11-05 10:15:50 字数 1818 浏览 920 评论 3

把服务器A作为代理服务器,内网所有用户通过代理A访问外网(http协议,其他暂不考虑),现在已经能实现其基本功能,但是代理效果不好,开网页有点卡,请问如何提升nginx正向代理速度?

nginx.cnf如下

worker_processes  8;


#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;


    server {
        listen       8080;
        server_name  X.X.X.X;

        #DNS 也用过国内的DNS,但开网页速度没有提升
        resolver 8.8.8.8;

        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        location / {

            proxy_pass $scheme://$http_host$request_uri;
            proxy_set_header Host $http_host;
            proxy_buffers 256 4K;
            proxy_max_temp_file_size 0;
            proxy_connect_timeout 30;
            proxy_cache_valid 200 302 10m;
            proxy_cache_valid 301 1h;
            proxy_cache_valid any 1m;
#           proxy_set_header X-Real-IP $remote_addr;
#           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空城仅有旧梦在 2021-11-08 16:55:51

用Nginx的主要原因是BOSS想在Nginx上做二次开发

清欢 2021-11-08 16:32:13

squid不支持么?

屌丝范 2021-11-08 12:41:32

第一次看到用 Nginx 做正向代理的,这也不是它的专长啊

Squid 呗。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文