我的Nginx配置如下。我同时安装了HTTP和HTTPS服务器。现在,我想将domain.com/admin下的所有HTTP重定向到HTTPS。我该怎么办?
我要重定向到HTTPS的URL。
domain.com/admin
domain.com/admin/mypage /
domain.com/admin/mypage/?id=1
domain.com/admin/mypage/sub?id=1
...
upstream web {
ip_hash;
server web:8000;
}
# portal
server {
listen 8000 default_server;
location / {
return 301 https://localhost$request_uri;
}
server_name localhost;
}
# portal (https)
server {
listen 443;
server_name localhost;
ssl on;
ssl_certificate /etc/nginx/conf.d/mynginx.crt;
ssl_certificate_key /etc/nginx/conf.d/mynginx.key;
location /media {
alias /media; # your Django project media files - amend as required
}
location /static {
alias /static; # your Django project static files - amend as required
}
location / {
proxy_pass http://web/;
}
}