如何在nginx/1.18.0 ubuntu中将http重定向到https



我想重定向我的域http://example.com到https://example.com

任何人都可以告诉我我做错了什么。

提前感谢---------:(

server {
listen 85;
listen [::]:85;
server_name example.com;
return 302 https://example.com$request_uri;
}
server {
listen 85 ;
listen [::]:85 ;

server_name example.com www.example.com; # managed by Certbot
location /static/ {
alias /home/shoaib/dir/static/;
}
location /media/ {
alias /home/shoaib/dir/media_root/;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/car.sock;
}

listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

我做了这样的事情:

return 301 https://$server_name$request_uri;

301用于永久重定向

I use this config
server {
listen 80;
listen myIP:443;
server_name www.exemple.fr exemple.fr;
return 301 https://$server_name$request_uri;
}
server{

listen               80;
listen               443 ssl ;
server_name          exemple.fr;


return 301 https://www.exemple.fr$request_uri;
}

这不起作用,我的域正在显示"欢迎使用nginx">

尝试使用superuser重新启动你的nginx,然后重试:

service nginx restart

https://phoenixnap.com/kb/nginx-start-stop-restart#htoc-强制重启nginx

对于重大配置更改,您可以强制完全重新启动Nginx。这支部队关闭了整个服务和子流程重新启动整个程序包。

相关内容

  • 没有找到相关文章

最新更新