要使用nginx作为代理服务器进行上网,需要进行以下步骤:

  1. 在nginx配置文件中添加以下内容:
http {
    proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m inactive=60m;
    proxy_temp_path /var/tmp/nginx;

    server {
        listen 80;
        server_name myserver.com;

        location / {
            proxy_pass http://localhost:8080;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
    }
}

其中,proxy_cache_pathproxy_temp_path是指定nginx缓存和临时文件的路径。server部分是指定监听的端口和域名,location部分是指定代理转发的地址和请求头信息。

  1. 在系统网络设置中指定nginx为代理服务器,可以使用以下命令:
export http_proxy=http://myserver.com:80
export https_proxy=http://myserver.com:80

其中,myserver.com是nginx服务器的域名或IP地址,80是监听的端口。

  1. 重启nginx服务器,使配置文件生效:
sudo service nginx restart

现在,所有的HTTP和HTTPS请求都会被转发到nginx服务器,并通过nginx服务器进行访问

nginx 代理上网设置

原文地址: https://www.cveoy.top/t/topic/d9H7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录