[英]How to redirect http to https in nginx/1.18.0 ubuntu
I want to redirect my domain http://example.com to https://example.com我想将我的域http://example.com重定向到https://example.com
Anybody can please tell me what I am doing wrong.任何人都可以请告诉我我做错了什么。
Thanks in advance-----------:)提前致谢 - - - - - -:)
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
}
i do something like this :我做这样的事情:
return 301 https://$server_name$request_uri;
301 is for permanent redirection 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;
}
this is not working my domain is showing "Welcome to nginx!"这不起作用我的域显示“欢迎使用 nginx!”
Try rebooting your nginx using superuser and try again:尝试使用超级用户重新启动 nginx 并重试:
service nginx restart
https://phoenixnap.com/kb/nginx-start-stop-restart#htoc-force-restart-nginx https://phoenixnap.com/kb/nginx-start-stop-restart#htoc-force-restart-nginx
For major configuration changes, you can force a full restart of Nginx.对于主要的配置更改,您可以强制完全重启 Nginx。 This force-closes the whole service and sub-processes, and restarts the whole package.这会强制关闭整个服务和子进程,并重新启动整个包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.