NGINX重写 - HTTPS / WWW [英] NGINX Rewrite - HTTPS/www
本文介绍了NGINX重写 - HTTPS / WWW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让我的网站,这样domain.com的每一个变化都会重定向到的https://www.domain .COM 。我使用的工具组合来做到这一点。其中是始于Nginx的配置文件:
I'm trying to get my site so that every variation of domain.com will redirect to https://www.domain.com. I'm using a combination of tools to do so .. One is the NGINX config file which begins with:
server {
listen 80;
server_name domain.com;
return 301 https://www.domain.com$request_uri;
}
server {
listen 80;
server_name localhost www.domain.com;
root /usr/local/nginx/html;
我也有一个规则集在我的CDN代理通过HTTPS协议的所有内容:
I've also got a rule set up in my CDN to proxy all content through HTTPS:
if ( $scheme = http ) {
REWRITE RULE ^ https://$http_host$request_uri permanent
}
几乎每一个变化,除了 https://domain.com ..它应该重定向到的 https://www.domain.com ,但它不会加载。
Almost every variation works, except https://domain.com .. it should redirect to https://www.domain.com, but it doesn't load.
推荐答案
这样的事情可以帮助:
server { # redirect _all_ http requests to https server
listen 80;
return 301 https://www.domain.com$request_uri;
}
server {
listen 443 ssl;
server_name localhost .domain.com ;
root /usr/local/nginx/html;
if ($host = domain.com) {
return 301 https://www.domain.com$request_uri;
}
}
这篇关于NGINX重写 - HTTPS / WWW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文