惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V2EX - 技术
V2EX - 技术
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
S
Securelist
P
Privacy & Cybersecurity Law Blog
Scott Helme
Scott Helme
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
Cyberwarzone
Cyberwarzone
Cisco Talos Blog
Cisco Talos Blog
量子位
博客园 - Franky
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Latest news
Latest news
T
Troy Hunt's Blog
N
News | PayPal Newsroom
Google Online Security Blog
Google Online Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
小众软件
小众软件
P
Palo Alto Networks Blog
Spread Privacy
Spread Privacy
C
Cyber Attacks, Cyber Crime and Cyber Security
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
L
Lohrmann on Cybersecurity
L
LINUX DO - 最新话题
D
Darknet – Hacking Tools, Hacker News & Cyber Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Last Watchdog
The Last Watchdog
S
Security @ Cisco Blogs
P
Privacy International News Feed
Last Week in AI
Last Week in AI
Microsoft Security Blog
Microsoft Security Blog
T
Tailwind CSS Blog
博客园_首页
云风的 BLOG
云风的 BLOG
V
Vulnerabilities – Threatpost
D
DataBreaches.Net
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
罗磊的独立博客
Engineering at Meta
Engineering at Meta
Forbes - Security
Forbes - Security
T
Tenable Blog

博客园 - 大西瓜3721

SVN分支/合并原理及最佳实践 Web.Config中Runtime节点-DLL版本冲突问题 工作问题 Vue资料 轻松实现WCF服务的构造函数依赖注入 WCF 依赖注入-- Attribute MVC视图分析 C#简单枚举和标志枚举的用法和区别 XDate Admin.NET框架资料 日志管理之log4net+Autofac 关于NopCommerce3.6版用户登录详解 AutoFac注册的动态实例 Named和Keyed NOP源码分析 六 NOP源码分析五---set的存储 NOP源码分析四 Nop源码分析三 NOP源码分析 二 NOP源码分析 一 NopCommerce的资料 IServiceCollection和IServiceProvider 控制反转——Autofac框架 精选10款C#/.NET开发必备类库 11个免费开源后台管理系统模板 H5连接蓝牙打印机打印小票 自定义控件 - 流式布局:TagFlowLayout MVC开源CMS DNS解析
nginx的安装&一个最简单的配置(windows和Centos)
大西瓜3721 · 2026-02-09 · via 博客园 - 大西瓜3721
      1. 下载 Nginx Windows 版本:
        官网地址:nginx.org/download/,选择最新稳定版(如 nginx-1.25.3.zip)。
      2. 解压到云服务器的本地目录(如 C:\nginx
      1. 打开配置文件:C:\nginx\conf\nginx.conf(用记事本或 VS Code 编辑)。
      2. 找到 http { ... } 块中的 server { ... } 节点,替换为以下内容(核心配置):

        复制代码

        http {
            include       mime.types;
            default_type  application/octet-stream;
        
            sendfile        on;
            keepalive_timeout  65;
        
            # 反向代理配置:将云服务器的80端口请求转发到实体服务器
            server {
                listen       80;  # 云服务器监听的端口(HTTP默认80)
                server_name  _;   # 若绑定域名,替换为你的域名(如 example.com)
        
                # 所有请求转发到实体服务器
                location / {
                    proxy_pass http://192.168.1.100:80;  # 实体服务器的内网IP和Web端口
                    proxy_set_header Host $host;        # 传递原始请求的Host头
                    proxy_set_header X-Real-IP $remote_addr;  # 传递客户端真实IP
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                }
        
                # 错误页面配置(可选)
                error_page   500 502 503 504  /50x.html;
                location = /50x.html {
                    root   html;
                }
            }
        
            # 配置HTTPS(可选,推荐)
            # server {
            #     listen       443 ssl;
            #     server_name  example.com;  # 绑定的域名
        
            #     ssl_certificate      C:/nginx/ssl/cert.pem;   # SSL证书路径
            #     ssl_certificate_key  C:/nginx/ssl/key.pem;    # 证书私钥路径
        
            #     location / {
            #         proxy_pass http://192.168.1.100:80;  # 同上,转发到实体服务器
            #         proxy_set_header Host $host;
            #         proxy_set_header X-Real-IP $remote_addr;
            #     }
            # }
        }

        复制代码

        • 关键参数说明:
          • proxy_pass:必须填写实体服务器的 内网 IP+Web 端口(如 http://192.168.1.100:80),确保云服务器能访问该地址。
          • 若实体服务器 Web 端口不是 80,需同步修改(如 http://192.168.1.100:8080)。
        如果需要修改Nginx配置,启动或者重启可以使用cmd命令,使用管理员身份打开控制台,然后使用cd进入到nginx的解压目录:
        重启:niginx.exe -s reload
        停止:nginx.exe -s stop

云服务器需要开放 80(HTTP)和 443(HTTPS,若配置)端口,否则外部无法访问:

      1. 打开 “控制面板 → 系统和安全 → Windows Defender 防火墙 → 高级设置”。
      2. 左侧选择 “入站规则”,右侧点击 “新建规则”:
        • 规则类型:选择 “端口” → 下一步。
        • 协议和端口:选择 “TCP”,填写 “特定本地端口”(如 80,若配置 HTTPS 则加 443,用逗号分隔) → 下一步。
        • 操作:选择 “允许连接” → 下一步。
        • 配置文件:默认全选(域、专用、公用) → 下一步。
        • 名称:填写 “允许 HTTP/HTTPS” → 完成。
    1. 在本地电脑浏览器中输入 云服务器的公网 IP(如 http://1.2.3.4),若能显示实体服务器的网页,则反向代理成功。
    2. 若访问失败,排查方向:
      • 云服务器是否能 ping 通实体服务器的内网 IP(如 ping 192.168.1.100)。
      • 实体服务器防火墙是否允许来自云服务器 IP 的 80 端口访问(需在实体服务器添加入站规则)。
      • Nginx 配置是否正确(检查 proxy_pass 地址是否错误,日志文件 C:\nginx\logs\error.log 可查错)。

在 Windows 系统的云服务器上实现反向代理,可以通过 Nginx for Windows 或 IIS(Windows 自带) 配置,以下是详细步骤(推荐 Nginx,配置更轻量灵活):

Windows 11:

1、下载nginx(版本为nginx-1.22.1)

https://nginx.org/en/download.html
nginx的目录最好不要有中文,不建议放到C盘。

2、最基础的配置nginx.conf如下:

  配置使用前后端分离。前端静态代码放到../../zym/html中,访问端口是80。后端接口的链接地址是8081端口。

  例如访问 http://localhost/data/index.html 实质是访问../../zym/html/data/index.html文件

  访问htpp://localhost/api/user/user_info 实质是访问http://localhost:8081/user/user_info接口,注意url中的api会被删掉。对于proxy中url中是否有斜杠,比较复杂,具体规则参看:https://www.jianshu.com/p/fc91f00016e4 。本文附录1也有介绍,完全copy自该链接。

nginx.conf

...
server {
    listen       80;
    server_name  localhost;

    location  /api/ {                         #规定好了,接口都是api开头的。
        proxy_pass   http://localhost:8081/;  #对于api的请求,通过nginx转发到8081端口
    }

    location / {
        root   ../../zym/html;       #放置静态代码的地方
        index  index.html index.htm; #默认主页
    }
server {
3、运行

启动nginx : start nginx
终止nginx: nginx -s stop
更新conf后需要刷新nginx(这个最常用,一般不会随便终止nginx):nginx -s reload

在Linux下安装(Centos 7)

其对于conf文件的配置与windows相同。只是路径根据实际情况修改一下即可。

1、去下载以下网址下载,然后放到linux去

http://nginx.org/download/nginx-1.22.1.tar.gz
或者直接用命令wget http://nginx.org/download/nginx-1.22.1.tar.gz

2、安装过程(参考https://www.cnblogs.com/Zzzyyw/p/17020893.html):

(1)新建目录并解压

    cd /usr/local/
    mkdir nginx
    cd nginx/ # 上传文件(或者用wget下载)
    ls 

(2)安装

    ls
    cd nginx-1.22.1
    ./configure --prefix=/usr/local/nginx # prefix后是安装路径;如果要支持https还需要加上 --with-https_ssl_module
#如果遇到error: the HTTP rewrite module requires the PCRE library.还需要先安装下面的libpcre3 libpcre3.dev

(3)启动
进入安装好的目录 /usr/local/nginx/sbin

    ./nginx # 启动
    ./nginx -s stop # 快速停止
    ./nginx -s quit # 优雅关闭,在退出前完成已经接受的连接请求
    ./nginx -s reload # 重新加载配置

附录1【Proxy,斜杠规则】:

结论,简单理解为:代理的地址在端口以后如果有东西(包括目录或者/),转发地址会去除location匹配的目录(根据匹配的字符,如果是/api则去除api,如果是/api/则去除/api/)
如果代理地址到端口就没了(没有目录或/),那么转发地址会保留匹配目录

(1)location和proxy_pass都带/,则真实地址不带location匹配目录
location /api/{proxy_pass http://127.0.0.1:8080/;}

访问地址:www.test.com/api/upload-->http://127.0.0.1:8080/upload

2.location不带/,proxy_pass带/,则真实地址会带/
location /api{proxy_pass http://127.0.0.1:8080/;}

访问地址: www.test.com/api/upload-->http://127.0.0.1:8080//upload

3.location带/,proxy_pass不带/,则真实地址会带location匹配目录/api/
location /api/{proxy_pass http://127.0.0.1:8080;}

访问地址: www.test.com/api/upload-->http://127.0.0.1:8080/api/upload

4.location和proxy_pass都不带/,则真实地址会带location匹配目录/api/
location /api{proxy_pass http://127.0.0.1:8080;}

访问地址: www.test.com/api/upload-->http://127.0.0.1:8080/api/upload

5.同1,但 proxy_pass带地址
location /api/{proxy_pass http://127.0.0.1:8080/server/;}

访问地址: www.test.com/api/upload-->http://127.0.0.1:8080/server/upload

6.同2,但 proxy_pass带地址,则真实地址会多个/
location /api{proxy_pass http://127.0.0.1:8080/server/;}

访问地址: www.test.com/api/upload-->http://127.0.0.1:8080/server//upload

7.同3,但 proxy_pass带地址,则真实地址会直接连起来
location /api/{proxy_pass http://127.0.0.1:8080/server;}

访问地址: www.test.com/api/upload-->http://127.0.0.1:8080/serverupload

8.同4,但 proxy_pass带地址,则真实地址匹配地址会替换location匹配目录
location /api{proxy_pass http://127.0.0.1:8080/server;}

访问地址: www.test.com/api/upload-->http://127.0.0.1:8080/server/upload

总结

1.proxy_pass代理地址端口后有目录(包括 / ),转发后地址:代理地址+访问URL目录部分去除location匹配目录
2.proxy_pass代理地址端口后无任何,转发后地址:代理地址+访问URL目录部