请求重定向到新域名(使用 return 指令)
1 | server { |
NGINX VARIABLES:
$scheme: request scheme, “http” or “https”.
$request_uri: full original request URI(with arguments).
请求的部分路径进行重定向(使用 rewrite 指令)
1 | server { |
以上配置重定向demo:
/download/cdn-west/media/file1 -> /download/cdn-west/mp3/file1.mp3
/download/cdn-west/media/file2.flv -> /download/cdn-west/mp3/file2.mp3
/download/cdn-est/audio/file3 -> /download/cdn-est/mp3/file3.ra
请求尝试性的进行重定向(使用 try_files 指令)
1 | location /images/ { |
以上配置重定向尝试demo:
假设请求URL为: http://www.domain.com/images/image1.gif,
将先尝试寻找文件: http://www.domain.com/images/image1.gif,
不存在时, 尝试重定向到目录: http://www.domain.com/images/image1.gif/
再不存在时, 最后重定向到路径: http://www.domain.com/images/default.gif下一个 location 规则, 表示匹配该条件时, 设置文件缓存时间为30秒.
添加与移除 www 前缀
1 | # add "www" prefix |
重定向全部流量至正确的域名
1 | server { |
强制全部请求都使用 SSL/TLS
1 | server { |
让 WordPress 网站启动美化的永久链接
1 | location / { |
阻止请求中不支持的文件拓展
1 | location ~ .(aspx|php|jsp|cgi)$ { |
1 | location ~ .(aspx|php|jsp|cgi)$ { |
配置自定义的重路由
1 | rewrite ^/listings/(.*)$ /listing.html?listing=$1 last; |