Nginx正向代理并在Windows上使用

Nginx正向代理并在Windows上使用

1. 配置Nginx正向代理

安装Nginx
  1. 在Linux服务器或本地机器上安装Nginx。
    • 对于Ubuntu:

      bash 复制代码
      sudo apt update
      sudo apt install nginx
配置Nginx
  1. 打开Nginx配置文件进行编辑(通常位于/etc/nginx/nginx.conf/etc/nginx/sites-available/default)。

  2. 添加或修改以下内容以设置正向代理:

    nginx 复制代码
    server {
        listen 9204;
        server_name localhost;
    
        location / {
            # Enable proxy
            proxy_pass http://12.22.133.12;
    
            # Set headers to preserve the client's original request information
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
    
            # Other proxy settings
            proxy_read_timeout 90;
            proxy_connect_timeout 90;
            proxy_redirect off;
        }
    }
  3. 保存并退出编辑器。

  4. 测试Nginx配置是否正确:

    bash 复制代码
    sudo nginx -t
  5. 重新加载Nginx以应用新配置:

    bash 复制代码
    sudo systemctl reload nginx

2. 在Windows上配置代理

打开代理设置
  1. 打开"设置"

    • 通过开始菜单或按 Win + I 键打开"设置"。
  2. 进入"网络和Internet"设置

    • 在"设置"中选择"网络和Internet"。
  3. 选择"代理"

    • 在左侧菜单中选择"代理"。
配置手动代理设置
  1. 启用手动代理

    • 在"手动代理设置"部分,将"使用代理服务器"开关打开。
  2. 输入代理服务器地址和端口

    • 在"地址"字段中输入Nginx服务器的IP地址(假设是192.168.1.100)。
    • 在"端口"字段中输入9204
  3. 保存设置

    • 单击"保存"以应用这些设置。

3. 验证代理设置

  1. 打开浏览器,尝试访问任意网页。
  2. 如果配置正确,浏览器的请求会通过Nginx正向代理服务器,并最终到达目标服务器12.22.133.12

4. 注意事项

  • 确保Nginx服务器能够访问目标服务器12.22.133.12
  • 可能需要在防火墙或路由器上允许9204端口的流量。
  • 如果网络环境较复杂,可能需要进一步的网络配置或调试。

完整的Nginx配置文件示例

以下是完整的Nginx正向代理配置文件内容:

nginx 复制代码
server {
    listen 9204;
    server_name localhost;

    location / {
        # Enable proxy
        proxy_pass http://12.22.133.12;

        # Set headers to preserve the client's original request information
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # Other proxy settings
        proxy_read_timeout 90;
        proxy_connect_timeout 90;
        proxy_redirect off;
    }
}

通过上述步骤,你可以成功配置Nginx作为正向代理服务器,并在Windows系统上设置代理,以使用这个代理服务器访问目标网站。

相关推荐
Archy_Wang_14 小时前
基于BaGet 构建NuGet私有库并实现类库打包到NuGet私有库
运维·jenkins
初听于你4 小时前
运维高级故障排除与恢复-SysRq
运维·服务器·安全
RPA机器人就用八爪鱼5 小时前
RPA自动化程序:企业数字化转型的智能引擎
运维·自动化·rpa
demodashi6665 小时前
Linux下ag搜索命令详解
linux·运维·windows
無识5 小时前
Linux-第四章web服务
linux·运维·服务器
fie88895 小时前
在CentOS 7上集成cJSON库的方法
linux·运维·centos
rit84324996 小时前
在Ubuntu上配置Nginx实现开机自启功能
数据库·nginx·ubuntu
爱吃橘的橘猫6 小时前
如何解决VMware虚拟机中Linux系统终端不显示ens33 inet IP地址的问题
linux·运维·服务器·虚拟机
佐杰6 小时前
Jenkins使用指南1
java·运维·jenkins
kyle~6 小时前
计算机系统---USB的四种传输方式
运维·c++·计算机系统