rewrite - nginx implements https for special urls
仅有的幸福
仅有的幸福 2017-05-16 17:21:05
0
2
638

The system with an interface all uses http requests. Now I like to use ssl for URLs with login passwd. For example, when the app calls os.test.com/a/p/login, it uses https requests but other requests. I still use http requests. Now I use openssl to configure the certificate private key, etc. But now every request uses https requests, such as
server {

listen      443;
server_name  os.test.com;
ssl on;
ssl_certificate /etc/ngx/conf.d/server.crt;
ssl_certificate_key /etc/ngx/conf.d/server.key;
location / {
    proxy_pass http://127.0.0.1:9988;
}

}
How should I modify this

仅有的幸福
仅有的幸福

reply all(2)
阿神

You have to write it separately. First create a server to specifically handle https requests, and then reverse proxy it based on the URL. Here is the code:

Handle non-https requests, https requests are reverse-proxyed out

server {

listen      443;
server_name  os.test.com;
location / {

}

location ~* .(login|passwd)$ {
    proxy_pass http://127.0.0.1:9999
}

}

Handling https requests

server{

listen 9999
server_name 127.0.0.1
ssl on;
ssl_certificate /etc/ngx/conf.d/server.crt;
ssl_certificate_key /etc/ngx/conf.d/server.key;
location / {
 
}

}

黄舟
# http
server {
    listen 80;
    
    location /login {
        rewrite ^  https://$host$request_uri permanent;
    }
}

# https
server {
    listen 443;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template