您好我想在用户尝试从http访问它时将所有页面重定向到https。我已经设置了ssl,但是如果网址只输入了http,则不会将它们重定向到https。我需要将它们重定向到所有页面的https。我如何实现这一目标?
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;
}
}
答案 0 :(得分:1)
为http 80
创建单独的配置,以重定向到https 443
。
server {
listen 80;
server_name *.website.local;
return 301 https://$host$request_uri;
}