# \#nginx

**URL:** https://www.isharkfly.com/tag/nginx/61.md

[Latest](https://www.isharkfly.com/latest.md) · [Categories](https://www.isharkfly.com/categories.md) · [Tags](https://www.isharkfly.com/tags.md)

---

## [Nginx 日志自动 rotate 的配置](https://www.isharkfly.com/t/nginx-rotate/10036)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [May 22, 2026, 4:00am UTC](https://www.isharkfly.com/t/nginx-rotate/10036 "2026-05-22T04:00:00Z")

</div>

Nginx 原生是不带有日志切割功能。 其依赖的是 Linux logrotate 进程。 配置位置为：vi /etc/logrotate.d/nginx 递归切割 默认 logrotate 不支持 \*\* 递归 多文件切割可以采用配置： /var/log/nginx/\*.log /var/log/nginx/\*/\*.log /var/log/nginx/\*/\*/\*.log { daily rotate 14 …

---

## [Nginx 如何配置 SSL](https://www.isharkfly.com/t/nginx-ssl/13953)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 1\
**Last updated:** [February 14, 2026, 3:40pm UTC](https://www.isharkfly.com/t/nginx-ssl/13953 "2026-02-14T15:40:59Z")

</div>

SSL 是目前网站的标配了，如果你还需要使用 Google 或者 Apple 的服务的话，你的网站要求必须使用 SSL。 Nginx 配置需要的文件 Niginx 配置需要 2 个文件。 Key 文件 Crt 文件 Key 文件是你自己生成的，或者使用 SSL 签发网站使用的 key 文件。 Crt 是 CA 机构根据你提供的 Key 文件通过校验后签发给你的，你需要将 Key 和 Crt 文件同时安装到的你的 Nginx 服…

---

## [Nginx 配置文件提示 upstream 路径错误](https://www.isharkfly.com/t/nginx-upstream/17299)

<div class="topic-metadata">

**Author:** [@hex](https://www.isharkfly.com/u/hex)\
**Replies:** 0\
**Last updated:** [May 15, 2025, 2:55pm UTC](https://www.isharkfly.com/t/nginx-upstream/17299 "2025-05-15T14:55:50Z")

</div>

错误的信息为： nginx: \[emerg\] "upstream" directive is not allowed here 原因和解决 这里的原因是改了配置文件upstream存的的位置不对所以导致报错的。 需要把 upstream 放入http 里面保存重启nginx就解决了。

---

## [Windows 中 nginx 的配置文件载入](https://www.isharkfly.com/t/windows-nginx/17298)

<div class="topic-metadata">

**Author:** [@hex](https://www.isharkfly.com/u/hex)\
**Replies:** 0\
**Last updated:** [May 15, 2025, 2:52pm UTC](https://www.isharkfly.com/t/windows-nginx/17298 "2025-05-15T14:52:55Z")

</div>

在默认按照情况下，Windows 和 Linux 的 Nginx 配置文件路径有出入。 Windows 默认没有添加 conf.d 目录，如果想和 Linux 的目录结构保持一致的话，需要在 conf 文件夹下添加一个 conf.d 目录。 目录结构就变成了上面的这种形式。 配置文件修改 当添加下面的目录后，需要修改nginx.conf 配置文件。 添加一个下面的配置。 include conf.d/\*.conf; …

---

## [Cloudflare 如何让 Nginx 获得真实 IP 地址](https://www.isharkfly.com/t/cloudflare-nginx-ip/17277)

<div class="topic-metadata">

**Author:** [@hex](https://www.isharkfly.com/u/hex)\
**Replies:** 0\
**Last updated:** [May 4, 2025, 5:06pm UTC](https://www.isharkfly.com/t/cloudflare-nginx-ip/17277 "2025-05-04T17:06:04Z")

</div>

在 Nginx 的配置文件中，添加下面的内容： set\_real\_ip\_from 173.245.48.0/20; set\_real\_ip\_from 103.21.244.0/22; set\_real\_ip\_from 103.22.200.0/22; set\_real\_ip\_from 103.31.4.0/22; set\_real\_ip\_from 141.101.64.0/18; set\_real\_i…

---

## [VUE 项目中的 CORS 问题](https://www.isharkfly.com/t/vue-cors/1542)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [January 15, 2021, 3:53pm UTC](https://www.isharkfly.com/t/vue-cors/1542 "2021-01-15T15:53:17Z")

</div>

CORS 是有点烦人的，但还是有解决办法。 最近一个项目提示了 CORS 的问题。 前端还是后端 要解决上面的问题，需要首先知道 CORS 的问题是前端还是后端。 经过排查后，这个问题是后端 Nginx 配置的问题。 add\_header Access-Control-Allow-Origin \*; add\_header Access-Control-Allow-Methods 'GET, …

---

## [Nginx SSL 测试错误](https://www.isharkfly.com/t/nginx-ssl/13250)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [January 30, 2021, 12:43am UTC](https://www.isharkfly.com/t/nginx-ssl/13250 "2021-01-30T00:43:38Z")

</div>

Nginx SSL 测试错误： PEM\_read\_bio\_PrivateKey() failed (SSL: error:1E08010C:DECODER routines::unsupported:No supported data to decode. Input type: PEM) 原因和解决 上面错误的原因是 Key 配置不对，或者是 crt 配置不对。 我们这里的配置问题是，上面的 Key 少了一个横线。 把这…

---

## [Nginx 检查配置选项](https://www.isharkfly.com/t/nginx/14180)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [November 1, 2022, 9:49pm UTC](https://www.isharkfly.com/t/nginx/14180 "2022-11-01T21:49:16Z")

</div>

对 Nginx 配置文件进行修改后，如果重启可能会因为配置文件的问题导致启动失败。 检查命令为： nginx -t 通过这个命令可以检查配置的状态。 如果没有问题，显示成功。

---

## [Nginx 在 Ubuntu 的虚拟主机配置不重定向问题](https://www.isharkfly.com/t/nginx-ubuntu/15482)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [March 6, 2024, 8:49am UTC](https://www.isharkfly.com/t/nginx-ubuntu/15482 "2024-03-06T08:49:13Z")

</div>

在 Nginx 的 Ubuntu 环境下配置的虚拟主机无法进行重定向。 配置也没有问题，后来发现就是主机名后面缺少了一个分号。 把分号加上后就可以重定向了。

---

## [Nginx 部署的虚拟主机如何使用 Let's Encrypt 来进行加密 https](https://www.isharkfly.com/t/nginx-lets-encrypt-https/14034)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [July 8, 2022, 9:56pm UTC](https://www.isharkfly.com/t/nginx-lets-encrypt-https/14034 "2022-07-08T21:56:54Z")

</div>

HTTPS 是现在网站的标配了，很多服务都是必须使用 https，如果你不使用的话，浏览器可能就不会对你非常友好了。 如果你不想使用商业的 CA 秘钥的话，你可以使用 Let’s Encrypt 来进行加密。 使用 Let’s Encrypt 唯一不好的地方就是每 3 个月要更新一次，当然你也可以使用自动的更新来处理就好了。 我们需要通过安装插件来实现： 获得 SSL 加密需要的 pem 秘钥。 设置 certbot 能自动更…

---

## [Nginx 主机配置文件中如何配置能够支持 IPv4 和 IPv6](https://www.isharkfly.com/t/nginx-ipv4-ipv6/14031)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [July 6, 2022, 6:35pm UTC](https://www.isharkfly.com/t/nginx-ipv4-ipv6/14031 "2022-07-06T18:35:12Z")

</div>

其实很简单的配置就可以了： server { listen 80; listen \[::\]:80; return ^ 301 https://$host$request\_uri; } 因为 IPv6 的表示方式和 IPv4 不一样，所以你需要新添加一行 listen \[::\]:80; 就可以了。 然后你在你的 DNS 上配置 IPv6，你的服务器也是可以正常解析地址的。

---

## [Nginx SSL: error:1410D0B 错误](https://www.isharkfly.com/t/nginx-ssl-error-1410d0b/16882)

<div class="topic-metadata">

**Author:** [@hex](https://www.isharkfly.com/u/hex)\
**Replies:** 0\
**Last updated:** [February 6, 2025, 4:06am UTC](https://www.isharkfly.com/t/nginx-ssl-error-1410d0b/16882 "2025-02-06T04:06:35Z")

</div>

在 Nginx 配置 SSL 的时候 nginx 提示错误： Restarting nginx: \[emerg\]: SSL\_CTX\_set\_cipher\_list("HIGH:!SSLv2:!SSLv3") failed (SSL: error:1410D0B9:SSL routines:SSL\_CTX\_set\_cipher\_list:no cipher match) nginx. 问题和解决 出现上面的问题是英文 nginx 在操…

---

## [Nginx 日志 access.log 清理](https://www.isharkfly.com/t/nginx-access-log/16878)

<div class="topic-metadata">

**Author:** [@hex](https://www.isharkfly.com/u/hex)\
**Replies:** 0\
**Last updated:** [February 6, 2025, 2:09am UTC](https://www.isharkfly.com/t/nginx-access-log/16878 "2025-02-06T02:09:19Z")

</div>

Nginx在涉及大流量时，会发生非常庞大的日志文件，包含access.log和error.log，日志会随着连接不断增加，到无限大。 如果日志文件太大，会导致Nginx运行缓慢，卡顿，也是存储资源的浪费。 这个日志还算好的，只有 1 个 G 左右。 我们有个虚拟域名，日志有 100 多 G。 可以使用下面的命令把这个日志文件给之间清理为 0，而不影响文件的权限和属性。 cat /dev/null \> access.log…

---

## [反代网站的疑问](https://www.isharkfly.com/t/topic/16247)

<div class="topic-metadata">

**Author:** [@CAKE\_NICE](https://www.isharkfly.com/u/CAKE_NICE)\
**Replies:** 2\
**Last updated:** [September 7, 2024, 12:38pm UTC](https://www.isharkfly.com/t/topic/16247 "2024-09-07T12:38:17Z")

</div>

如题，我想要反代一个8443端口，且需要特定路径 而且是有SSL证书的网站 Nginx的反代不成功，估计这种方法不太行 进阶操作 可以将固定的Cookie给用户使用

---

## [NGINX 反向代理 CORS](https://www.isharkfly.com/t/nginx-cors/15554)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [March 26, 2024, 6:45pm UTC](https://www.isharkfly.com/t/nginx-cors/15554 "2024-03-26T18:45:16Z")

</div>

我遇到了一个问题就是 Nginx 是作为反向代理服务器部署的，但因为 Nginx 的配置导致 CORS 问题。 在这个时候我们可以对 Nginx 的配置文件进行修改： 在 location 后添加下面的内容： add\_header Access-Control-Allow-Origin \*; add\_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; add\_head…

---

## [Failed (13: Permission denied) while connecting to upstream, client 错误](https://www.isharkfly.com/t/failed-13-permission-denied-while-connecting-to-upstream-client/15353)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [January 23, 2024, 2:20am UTC](https://www.isharkfly.com/t/failed-13-permission-denied-while-connecting-to-upstream-client/15353 "2024-01-23T02:20:36Z")

</div>

NGINX 在重启后发现有下面的错误信息： failed (13: Permission denied) while connecting to upstream, client 问题和解决 这个显然又是另外的一个 SELinux 错误。 修改 SELinux 的配置为：SELINUX=permissive 然后保存退出。 文件的路径为： sudo vi /etc/selinux/config

---

## [Nginx 如何配置虚拟主机](https://www.isharkfly.com/t/nginx/14027)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [July 5, 2022, 3:29pm UTC](https://www.isharkfly.com/t/nginx/14027 "2022-07-05T15:29:11Z")

</div>

Nginx 我们更多是用作反向代理。 所以在 Nginx 上面我们会可能配置比较多的虚拟主机。 配置文件夹路径 配置文件的文件夹路径为： /etc/nginx/conf.d 所有虚拟主机的配置文件都放在这个文件夹中。 配置文件 配置文件应该是 conf 为结尾的。 比如说我们需要配置一个为 src.ossez.com 的虚拟主机，那么我们可以将配置文件命名为 src.ossez.com.conf 然后将所有有关这个虚拟主机…

---

## [Nginx 烦人的 403 错误](https://www.isharkfly.com/t/nginx-403/14029)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [July 5, 2022, 8:30pm UTC](https://www.isharkfly.com/t/nginx-403/14029 "2022-07-05T20:30:18Z")

</div>

当你设置好 Nginx 服务器后，并且你也相信你的虚拟主机都设置好了。 但是你就是老实到一个 403 的错误，这个绝大部分情况是因为 SELinux 造成的。 解决办法 首先运行命令： setenforce 1 然后查看下你的程序能不能通过 URL 正常的访问。 如果能够正常访问的话，这个就铁定是 SELinux 的问题了。 你还可以运行下面的命令，将 http 加入到信任的列表中： semanage permiss…

---

## [Fedora 开机自启动 Nginx](https://www.isharkfly.com/t/fedora-nginx/14026)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [July 5, 2022, 3:24pm UTC](https://www.isharkfly.com/t/fedora-nginx/14026 "2022-07-05T15:24:21Z")

</div>

曾经我们还尝试使用脚本让操作系统开机自动启动 nginx。 在新版本的 Linux 中我们不需要这样做了。 直接运行下面的命令： $ sudo systemctl enable nginx 就可以了。 服务器上的输出为： \[fedora@api-usreio-1 ~\]$ sudo systemctl enable nginx Created symlink /etc/systemd/system/multi-user.tar…

---

## [反向代理 413 Request Entity Too Large 问题](https://www.isharkfly.com/t/413-request-entity-too-large/13963)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [May 13, 2022, 6:18pm UTC](https://www.isharkfly.com/t/413-request-entity-too-large/13963 "2022-05-13T18:18:45Z")

</div>

如果在服务器上使用了反向代理。 你可能会收到下面的错误信息： 413 Request Entity Too Large errors\`。 问题和解决 问题的原因就是反向代理服务器针对 HTTP 访问的时候有限制， Nginx 在 Nginx 的配置文件中，添加下面的内容 client\_max\_body\_size 100M; 上面的配置信息显示了具体的配置位置。 在默认情况下 Nginx 配置的 client\_max\_bod…

---

## [Nginx 的日志](https://www.isharkfly.com/t/nginx/13956)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [May 8, 2022, 1:23pm UTC](https://www.isharkfly.com/t/nginx/13956 "2022-05-08T13:23:25Z")

</div>

Nginx 的日志主要有 2 个，一个是 access.log， 一个是 error.log。 如果你不进行任何配置的话，这 2 个日志将会使用默认的日志配置，这个日志将会位于 /var/log/nginx 目录中。 针对虚拟主机的配置 如果你使用了 Nginx 为虚拟主机的话。 那么你可以在你的虚拟主机的配置文件中配置针对每一个特定的虚拟主机输出的日志路径。 例如我们针对虚拟主机的配置。 这样针对这个虚拟主机的所有…

---

## [正向代理与反向代理](https://www.isharkfly.com/t/topic/13955)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [May 7, 2022, 11:24pm UTC](https://www.isharkfly.com/t/topic/13955 "2022-05-07T23:24:56Z")

</div>

我们都知道 Nginx 是常用的反向代理服务器。 但是什么是正向代理，什么是反向代理有时候概念好像不太好理解。 我们画了一个不好看的图来解释代理和反向代理 代理的理解 我们的简单理解就是这个代理是正向还是反向与代理服务器设置的位置有关。 这个代理服务器可能就是你计算机或者服务器上的进程。 正向代理 举例来说就是如果代理服务器离你很近，如果没有这个服务器你就没有办法访问网站，你必须要通过这个服务器才能访问所有的互联网资源的话…

---

## [Nginx 和 Apache 配置 SSL 文件签名的不同](https://www.isharkfly.com/t/nginx-apache-ssl/13954)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [May 7, 2022, 10:46pm UTC](https://www.isharkfly.com/t/nginx-apache-ssl/13954 "2022-05-07T22:46:05Z")

</div>

Apache 配置 SSL 需要 3 个文件。 Nginx 配置 SSL 只需要 2 个文件。 原因 这是因为 Nginx 将 Apache 配置需要的 3 个文件中的 2 个文件合并成一个文件了。 Apache Apache 配置需要的 3 个文件为： SSLCertificateKeyFile /etc/pki/tls/ossez\_com/ossez\_com.key SSL…

---

## [Nginx 和 Nginx Plus 的区别](https://www.isharkfly.com/t/nginx-nginx-plus/13950)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [May 6, 2022, 6:45pm UTC](https://www.isharkfly.com/t/nginx-nginx-plus/13950 "2022-05-06T18:45:59Z")

</div>

虽然 Apache 的 httpd 也可以做反向代理。 但是在效率和配置上确实不如 nginx，因此我们也将我们的反向代理服务换成了 nginx。 在选择版本的时候遇到了：到底是选择 Nginx 还是 Nginx Plus 的问题。 简单来说就是： Nginx Plus 相当于付费版本的 Nginx。 提供了更多的功能，针对企业需要的一些服务进行了优化。 有关功能的比较页面，请参考： https://www.nginx.com…

---

## [Nginx 如何将所有 HTTP 的流量转移到 HTTPS](https://www.isharkfly.com/t/nginx-http-https/13949)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [May 5, 2022, 9:56pm UTC](https://www.isharkfly.com/t/nginx-http-https/13949 "2022-05-05T21:56:42Z")

</div>

我们都知道，如果希望将 http 的访问自动切换到 https ，其实有多种方法可以去做。 比如说在 DNS 服务器上直接配置。 主要目的就是让网站只支持 https 的方法。 Nginx 的配置方法 在 Nginx 的虚拟主机配置文件中，只需要下面的 2 句话就可以了。 server { listen 80; server\_name src.ossez.com; retu…

---

## [Fedora 35 开机自启动 nginx](https://www.isharkfly.com/t/fedora-35-nginx/13948)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [May 5, 2022, 9:41pm UTC](https://www.isharkfly.com/t/fedora-35-nginx/13948 "2022-05-05T21:41:22Z")

</div>

Fedora 35 配置开机自动启动 nginx 的方式非常简单。 只需要 sudo systemctl enable nginx 运行就可以了。 其实所有针对 Fedora 35 版本的服务，都只需要执行上面的命令就可以配置服务让服务开机自动启动了。

---

## [开机自启动 nginx](https://www.isharkfly.com/t/nginx/9395)

<div class="topic-metadata">

**Author:** [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Replies:** 0\
**Last updated:** [October 26, 2012, 2:48am UTC](https://www.isharkfly.com/t/nginx/9395 "2012-10-26T02:48:49Z")

</div>

这里使用的是编写 shell 脚本的方式来处理 vi /etc/init.d/nginx (输入下面的代码) #!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.0.0.2 version. # chkconfig: - 85 15 # description: Nginx is a high-performance web and prox…
