小编bde*_*ham的帖子

nginx 的“主线”和“稳定”分支有什么区别?

nginx 网络服务器似乎有两个活动分支:一个“主线”分支(当前为 1.9.x)和一个“稳定”分支(当前为 1.8.x)。谁能提供官方资料来描述这两个分支之间的区别以及如何在它们之间进行选择?

nginx

68
推荐指数
1
解决办法
4万
查看次数

有没有一种优雅的方法可以一次阻止一堆推荐人?

为了防止引用垃圾邮件,我的 nginx.conf 包含这样的部分:

if ($http_referer ~* spamdomain1\.com) {
    return 444;
}
if ($http_referer ~* spamdomain2\.com) {
    return 444;
}
if ($http_referer ~* spamdomain3\.com) {
    return 444;
}
Run Code Online (Sandbox Code Playgroud)

如果用户设置了这些引用之一,这些规则告诉 nginx 只是关闭连接。有没有更优雅的方法来做到这一点?我可以定义这些域的列表,然后说“如果引用者在此列表中,则返回 444”吗?

nginx

23
推荐指数
2
解决办法
2万
查看次数

使用 nginx 从 URL 中删除尾部斜杠

我希望我网站上的以下 URL 是等效的:

/foo/bar
/foo/bar/
/foo/bar/index.html
Run Code Online (Sandbox Code Playgroud)

此外,我希望后两个表单发出 HTTP 301 重定向到第一个表单。我只是服务静态页面,按照第三种形式排列。(换句话说,当用户请求时,/foo/bar他们应该在 处接收文件/usr/share/.../foo/bar/index.html)。

nginx.conf目前包含以下内容:

rewrite ^(.+)/$ $1 permanent;
index index.html;
try_files $uri $uri/index.html =404;
Run Code Online (Sandbox Code Playgroud)

这适用于 的请求/foo/bar/index.html,但是当我请求/foo/bar/foo/bar/Safari 告诉我“发生了太多重定向”——我假设存在无限重定向循环或类似的东西。如何让 nginx 以我描述的方式将 URL 映射到文件?

编辑:我的完整配置

这是我的nginx.conf域名全部替换为“example.com”。

user www-data;
worker_processes 1;
pid /run/nginx.pid;

events {
  worker_connections 768;
}

http {
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  server_tokens off;

  server_names_hash_bucket_size 64;

  include /etc/nginx/mime.types;
  default_type application/octet-stream;

  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log; …
Run Code Online (Sandbox Code Playgroud)

nginx

17
推荐指数
3
解决办法
5万
查看次数

如何使用错误的 Host 标头集阻止请求?

我使用 nginx 来服务我的网站。我想阻止所有带有与我的站点域不匹配的 HTTP“主机”标头的请求。

更具体地说,我的 nginx.conf 包含这两个服务器块:

server {
    # Redirect from the old domain to the new domain; also redirect
    # from www.newdomain.com to newdomain.com without the "www"
    server_name www.olddomain.com olddomain.com www.newdomain.com;
    listen 80;
    return 301 $scheme://newdomain.com$request_uri;
}

server {
    server_name newdomain.com localhost;
    listen 80;

    # Actual configuration goes here...
}
Run Code Online (Sandbox Code Playgroud)

我想阻止(即“返回”444 状态代码)主机不是 www.olddomain.com、olddomain.com、www.newdomain.com 或 newdomain.com 的任何流量。我怎样才能做到这一点?

nginx

13
推荐指数
1
解决办法
8890
查看次数

对我系统上的磁盘进行原子写入的大小是多少?

在该文件access_log指令,Nginx的文件说,

缓冲区大小不得超过对磁盘文件进行原子写入的大小。

我如何确定我的系统上的这个大小是多少?

linux nginx

11
推荐指数
1
解决办法
3292
查看次数

标签 统计

nginx ×5

linux ×1