[英]NGINX redirect http to https
Hi I would like to redirect all pages when a user try to access it from http to https. 嗨,当用户尝试从http访问https时,我想将所有页面重定向。 I already setup the ssl but if the url just typed in the http it doesn't redirect them to https.
我已经设置了ssl,但是如果url仅在http中键入,则不会将其重定向到https。 I need to redirect them to https for all pages.
我需要将它们重定向到所有页面的https。 How do I achieve this?
我该如何实现?
server {
listen 80;
listen 443 ssl;
server_name *.website.local;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
root /var/www/website/public;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
}
Create a separate config for http 80
to redirect to https 443
. 为
http 80
创建一个单独的配置,以重定向到https 443
。
server {
listen 80;
server_name *.website.local;
return 301 https://$host$request_uri;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.