运行Nginx + Centos 7.2 + WordPress
我正在为我的域安装SSL,并且当我在我的sererconfiguration中设置端口来listen 443 ssl; 当我访问域时,它会提示我“Welcome to nginx”
但是,如果我改回来listen 80; 它会显示我的网站。
这是我的服务器域configuration:
server{ listen 443 ssl; server_name domain.com www.domain.com; root /var/www/data/domain.com/public_html/; index index.php index.html index.htm; client_max_body_size 500M; ssl on; ssl_certificate /etc/nginx/ssl/ssl-bundle.crt; ssl_certificate_key /etc/nginx/ssl/domain.key; ssl_prefer_server_ciphers on; location / { try_files $uri $uri/ /index.php?q=$uri&$args; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/data/domain.com/public_html/; } location ~ \.php$ { try_files $uri $uri/ /index.php?q=$uri&$args; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
这里是我的nginx.conf:
user nginx; worker_processes 1; error_log /var/log/nginx/error.log; pid /run/nginx.pid; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; 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; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*.conf; server_names_hash_bucket_size 64; }
我花了最后4天试图让SSL工作,嗯,我没那么幸运。
另外,当我添加return 301 https://$host$request_uri; 到我的域configuration,我只是得到“太多的redirect”错误。
编辑:
所以,正如你可以在我的nginx.conf底部看到的那样,它包含了/etc/nginx/conf.d/*所以由于某种原因它读取了我的域configuration,并且跳过了这个过程,并且在'/ etc / nginx / conf.d / *'代替。
那么,还在想什么我可以做不同的做法。
那么,Alexey Ten在他的评论中给出了答案:如果你打电话给你的网站而不明确使用https(“ https://www.domain.com ”)你的服务器正在通过端口80寻址,而没有redirect你的服务器在443不会服务任何东西。
你把redirect指令放在哪里? 您必须将其写入另一个服务器块,如下所示:
server { listen 80; return 301 https://$host$request_uri; }
这将所有内容redirect到https。 如果您只想将domain.com的请求redirect到https,则可以向该块添加服务器名称伪指令(“server_name domain.com http://www.domain.com;”)。