当我访问nginx.conf
上的网站时,以下http://my-domain-name.com
为什么不重定向?
root@atlantis-server:~# cat /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 80;
server_name atlantis_server;
return 301 https://$host$request_uri;
}
server {
server_name atlantis_server;
listen 443 ssl;
##
# SSL Settings
##
ssl_certificate /root/certs/atlantis-server/some.cer.b64;
ssl_certificate_key /root/certs/atlantis-server/some.key;
ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
}
}
在https://my-domain-name.com
上的访问已正确完成!
答案 0 :(得分:2)
可以尝试使用此代码
server {
listen [::]:80;
listen 80;
server_name my-domain-name.com www.my-domain-name.com ;
# redirect http to https www
return 301 https://$host$request_uri;
}