nginx 网络服务器似乎有两个活动分支:一个“主线”分支(当前为 1.9.x)和一个“稳定”分支(当前为 1.8.x)。谁能提供官方资料来描述这两个分支之间的区别以及如何在它们之间进行选择?
为了防止引用垃圾邮件,我的 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”吗?
我希望我网站上的以下 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 来服务我的网站。我想阻止所有带有与我的站点域不匹配的 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 的任何流量。我怎样才能做到这一点?