我正在尝试将所有 http 流量重定向到 https。下面是我的配置。流量重定向但它添加了 443 到导致我的应用程序失败的路由。
http://mysite.com/login
变成
https://mysite.com:443/login
这是我的 nginx 配置文件:
server {
listen 80;
server_name mysite.com www.mysite.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443;
ssl on;
ssl_certificate /etc/ssl/mysite.com.crt;
ssl_certificate_key /etc/ssl/server.key;
server_name mysite.com www.mysite.com;
root /var/www/html/mysite/public/;
client_max_body_size 150M;
location /
{
index index.php index.html index.htm;
}
# Enforce No WWW - I put this in an include:
# include /etc/nginx/includes/enforce_non_www;
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
# Check if file exists
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
# catch all
error_page 404 /index.php;
# The PHP Inclusion Block
# include /etc/nginx/includes/php;
location ~ \..*/.*\.php$
{
# I'm pretty sure this stops people trying to traverse your site to get to other PHP files
return 403;
}
location ~ \.php(.*)$
{
# Pass the PHP files to PHP FastCGI for processing
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Deny Any Access to .htaccess Files That May Be Present (not usually in issue in Laravel)
# include /etc/nginx/includes/deny_htaccess;
location ~ /\.ht
{
deny all;
}
}