我正在开发一个网站,我刚刚在生产网站上安装了
ssl
(我以前从未这样做过)。当我加载开发网站时,页面重定向到 https 并中断,因为开发网站上未安装 https。
Nginx(生产):
server{
listen 80;
server_name ezel.io;
root /var/www/ezel.io/public;
location ~ /.well-known {
allow all;
}
rewrite ^ https://$server_name$request_uri? permanent;
}
Nginx(开发):
server {
listen 80;
server_name local.ezel.io;
root /home/ryan/Documents/www/ezel.io/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
在我的开发机器上,我的主机文件中还有以下内容:
127.0.0.1 local.ezel.io
什么会导致我从 http://local.ezel.io 转到 https://local.ezel.io?
我认为问题在于您启用了 https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security 一次,现在您的浏览器坚持尝试 HTTPS。
试试这个:http://classically.me/blogs/how-clear-hsts-settings-major-browsers
此外,尝试 ping
local.ezel.io
以确保它确实是您的本地主机,而不是实际的 ezel.io
。
示例脚本 nginx :
server
{
listen 443 default ssl;
listen [::]:443 ssl;
root /var/www/html/api_mobile/public;
include snippets/ssl-params.conf;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.html index.php index.htm index.nginx-debian.html;
server_name sitename.com;
charset utf-8;
location / {
if ($scheme ="http") {
# redirect all non api traffic to https block
return 301 https://$server_name$request_uri;
}
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
ssl_certificate /etc/letsencrypt/live/sites/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/site/privkey.pem; # managed by Certbot
}
关于计划条件:
if ($scheme ="http")
{
# redirect all non api traffic to https block
return 301 https://$server_name$request_uri;
}
它在一个端口 443 https 上重定向的核心强制 http 到 https