大家好。购买了以前由另一个人拥有的域。旧域的 google 索引中有带有 https 的页面。我要上传到这个域的网站在 http 上工作,所以当我从 https 访问页面时需要重定向到 http。我搜索了互联网,尝试了很多选项 - 它不起作用。
这是我的 nginx 配置:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
access_log off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 10M;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen myip:80;
server_name .mysite12.com;
location / {
root /home/site12;
index index.php;
if ($scheme = https) {
return 301 http://$host$request_uri;
}
if (!-e $request_filename) {
rewrite ^ /index.php last;
break;
}
}
location ~ \.php$ {
root /home/site12;
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
}
添加
if ($scheme = https) {
return 301 http://$host$request_uri;
}
在我看来,这是最合乎逻辑的选择,但它不起作用......帮助我从 http 重定向到 https
如果没有有效的证书,将无法进行重定向。只有在建立 https 连接后,重定向才会起作用。
还没有人取消 LetsEncrypt。