以下是我的Nginx服务器配置(不工作)。我需要将https non www重定向到www。因此,当我访问站点https://example.com时,它会将我重定向到https://www.example.com。
server {
listen 443 ssl
server_name example.com;
return 301 https://www.example.com$request_uri;
}编辑:我的负载均衡:

我正在使用AMI Linux在AWS中运行Ruby on Rails应用程序。谢谢!!
发布于 2016-02-24 13:15:07
请在您的nginx.conf文件中使用以下配置。它对我来说工作得很好。
server {
listen 80;
server_name www.example.com example.com;
location / {
index index.html;
root /usr/share/nginx/html; #the location of your app folder
}
if ($http_x_forwarded_proto = 'http') {
return 301 https://www.example.com$request_uri;
}
}发布于 2016-02-24 13:15:53
如果您只想重定向GET请求,并为非GET请求抛出405 (不允许使用方法):
server {
listen 443 ssl;
server_name example.com;
if ($request_method = GET) {
return 301 https://www.example.com$request_uri;
}
return 405;
}
server {
listen 443 ssl;
server_name www.example.com;
# locations
}如果您想要所有请求(GET、POST等)重定向,这是不可能的,我建议您尝试Akshath的方法。
https://stackoverflow.com/questions/35593475
复制相似问题