NGINXredirectHTTPS部分工作

我尝试在https上redirect所有stream量。 我使用AWS,乘客+ NGINX。

到目前为止,我的智能手机(Android),铬最后的版本: http : //server_name.comredirect到https …

在家里我的电脑铬最后版本reddirect以及。 但在其他计算机上,它不会redirect。

当然,无处不在的https://server_name.com工作时正确访问。

这里是我的conf:

#user adrien; events { worker_connections 768; # multi_accept on; } http { passenger_root /home/ubuntu/.rvm/gems/ruby-2.3.1/gems/passenger-5.0.30; passenger_ruby /home/ubuntu/.rvm/gems/ruby-2.3.1/wrappers/ruby; server_tokens off; add_header X-Frame-Options SAMEORIGIN; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header Content-Security-Policy "default-src 'self'; script-src 'self' https://bam.nr-data.net https://js-agent.newrelic.com 'unsafe-inline' 'unsafe-eval' https://ssl.google-analytics.com https://assets.zendesk.com https://connect.facebook.net; img-src 'self' https://secure.gravatar.com https://ssl.google-analytics.com https://s-static.ak.facebook.com https://assets.zendesk.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://assets.zendesk.com; font-src 'self' https://themes.googleusercontent.com; frame-src https://assets.zendesk.com https://www.facebook.com https://s-static.ak.facebook.com https://tautt.zendesk.com; object-src 'none'"; ssl_session_cache shared:ssl_session_cache:10m; server { listen 80 default_server; server_name xeralis.eu www.xeralis.eu; return 301 https://$host$request_uri; } server { listen 443; server_name xeralis.eu www.xeralis.eu; ssl on; ssl_session_timeout 5m; ssl_certificate /etc/ssl/nginx.crt; ssl_certificate_key /etc/ssl/nginx.key; ssl_protocols TLSv1.2 TLSv1.1 TLSv1; ssl_prefer_server_ciphers on; ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH'; ssl_dhparam /etc/ssl/dhparams.pem; resolver 8.8.8.8; # Rails add its own headers with force_ssl: true # add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; passenger_enabled on; passenger_friendly_error_pages on; rails_env development; root /home/ubuntu/www/rails/mercipublic/public; location /cable { passenger_app_group_name gorails_websocket; passenger_force_max_concurrent_requests_per_process 0; } location ~* ^/assets/ { gzip_static on; expires max; add_header Cache-Control public; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } keepalive_timeout 10; } } 

这个conf在SSL实验室给了我一个'A'的标记。 我可以做些什么来使我的网站从任何地方工作,http总是redirect到HTTPS

**编辑标题以响应http **

示范:
警告:使用-X / – 请求将自定义HTTP方法设置为HEAD可能无法使用警告:您想要的方式。
考虑使用-I / – 头。
curl:(7)无法连接到xeralis.eu端口80:连接被拒绝

与-I:
无法连接到xeralis.eu端口80:连接被拒绝

**编辑标头以回应https **

警告:使用-X / – 请求将自定义HTTP方法设置为HEAD可能不会
工作警告:你想要的方式。 考虑使用-I / – 头。
HTTP / 1.1 200
OKdate:2017年2月28日(星期二)22:36:59 GMT
Content-Type:text / html; 字符集= utf-8的
内容长度:11339连接:保持活动
Set-Cookie:AWSALB = 1AbTZpK / eslWt + 5VDBK1wqKygcY30U73T36e8987HvJVTR2iE4jqD2W51m + pwEvvzd + Y9wazTTG1rrh2T0BNsNE + TDB9mD5Bl1EADEFWL9hxlHQsqOuQ6 / p6qXjy; 到期时间=星期二,2017年3月07日22:36:59 GMT; path= /
状态:200 OK
Cache-Control:max-age = 0,私有,必须重新validation
ETag:W /“4b9c4360372ca37d2116059c2018043b”
X-Frame-Options:SAMEORIGIN
X-XSS-Protection:1; 模式=块
X-Content-Type-Options:nosniff
X-Runtime:0.081279
X-请求-ID:288d1d28-b6ae-420F-9c87-9e016873c900的Set-Cookie:_mercipublic_session = aEdtcW9NRFlQSytSL1VFTmFoVlNHd0RCUXk1ZzFCaFo3ak5RUGQ0SmRocC9MVmxmd0VnNWxZem5sUDlySTUxVDlDVGFIZTRBbVFwRGwvOXpSNmhReTh6Z2d4MkpVQWhVL2Z6bGJ3UWt3U3BqRXNsMjZSUnNXOW55OEtOTk9GUzdzbERnSWJXR3c2Y2F1dUF2RmRNWlhBPT0tLWUyYWl5aWlsT3lUS2s2YXkya0JJNVE9PQ%3D%3D – e896f790c978b429d6644055f2e8c827d07657c2; path= /; 仅Http
X-Powered-By:Phusion Passenger 5.0.30
服务器:nginx + Phusion Passenger 5.0.30
X-Frame-Options:SAMEORIGIN
X-Content-Type-Options:nosniff
X-XSS-Protection:1; 模式=块
Content-Security-Policy:default-src'self'; script-src'self'https : //bam.nr-data.net https: //js-agent.newrelic.com'unsafe-inline''unsafe-eval'https : //ssl.google-analytics.com https ://assets.zendesk.com https://connect.facebook.net ; img-src'self'https : //secure.gravatar.com https://ssl.google-analytics.com https://s-static.ak.facebook.com https://assets.zendesk.com ; style-src'self''unsafe-inline'https: //fonts.googleapis.com https://assets.zendesk.com ; font-src'self'https ://themes.googleusercontent.com ; frame-src https://assets.zendesk.com https://www.facebook.com https://s-static.ak.facebook.com https://tautt.zendesk.com ; object-src'none'

**编辑2半问题解决**问题来自AWS的ELB。 443我只有一个听众。所以当然是阻止了80 …

现在我唯一要解决的最后一件事就是为什么在HTTP和HTTPS都工作时redirect不起作用

试试这个替代块,它删除$主机,并硬编码redirect到的URL。 我build议你试试这个的原因是$ host的定义

按照以下优先顺序:来自请求行的主机名,来自“主机”请求头字段的主机名,或与请求匹配的服务器名

 server { listen 80 default_server; server_name xeralis.eu www.xeralis.eu; return 301 https://www.xeralis.eu$request_uri; } 

如果这不起作用,请编辑您的问题,以包括发生的情况,无论是成功或失败。 “curl -X HEAD -i(URL)”通常是这样做的。 显示匹配的访问日志条目。