【发布时间】:2014-09-28 08:24:17
【问题描述】:
我已经在 ubuntu 服务器 12.04 lts 中通过 nginx 实现了 https 强制。 nginx版本:nginx/1.1.19。我在路径 /etc/nginx/conf.d/https.conf 中添加了一个 conf 文件,并从 nginx.conf 中包含它。它看起来像:
server {
listen *:80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
其余的配置只是默认的:
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
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;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
当通过 www.example.com 访问时,它会正确地将我重定向到 web 的 https 版本。
相反,当通过 example.com 访问时,它只是通过 http 版本而应该重定向到 https://www.example.com。
配置有问题吗?应用服务器监听 9000 和 9443 端口(分别为 http 和 https),并通过这些规则由 iptables 转发:
-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 9000
-A PREROUTING -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 9443
提前致谢
【问题讨论】:
-
请发布您的完整 nginx 配置。
-
那里,它们是默认设置
-
如果您使用
site.com到达那里是否有效?这就是您在server_name行server_name site.com www.mysite.com;中的内容。 -
抱歉打错了:通过 www.mysite.com 访问时,它正确地将我重定向到 https 版本的网络。相反,当通过 mysite.com 访问时,它只是通过 http 版本,什么时候应该重定向到 mysite.com。
标签: redirect nginx playframework-2.1