我有 nginx 服务器作为反向代理。我想同时监听端口 80 (http) 和 443 (https)。我希望 http 和 https 的请求路径是不同的,因为它们向客户端提供不同的信息。
/api/plain_http/xxxx
和 /api/ssl_http/yyyy
前者 (http) 不会提供任何敏感信息,因此可以使用 http。后者可能包含敏感内容,因此我们希望强制执行 TLS 和
authz
/authn
。
我确信 NGINX 反向代理可以做到这一点,但我想再次确认配置文件将是什么样子来支持这一点。
为了确认您的查询,我相信 Nginx 可以配置为管理 HTTP 和 HTTPS 上的请求。我们只需要 HTTPS 配置所需的 SSL 证书和 SSL 证书密钥。 以下是示例配置:
server {
listen 80;
server_name your_domain.com;
location /api/plain_http/ {
# Proxy pass to the backend server handling HTTP requests
proxy_pass http://backend_http_server;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 443 ssl;
server_name your_domain.com;
ssl_certificate /path/to/your/certificate.crt;
ssl_certificate_key /path/to/your/certificate.key;
location /api/ssl_http/ {
# Add or remove Authenticate as per your requirement.
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/.htpasswd;
# Proxy pass to the backend server handling HTTPS requests
proxy_pass http://backend_https_server;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
希望这有帮助!