我将解析服务器迁移到基于以下文档的DigitalOcean Ubuntu液滴:
对于解析服务器的nginx代理(https)请求,我遇到了问题。
如果我在液滴上打开端口1337,并将解析http请求配置为直接转到解析服务器(http://example.com:1337/parse),那么所有这些都可以正常工作。
如果我将解析http请求配置为转到https://example.com/parse,则nginx无法代理解析服务器的请求。
nginx返回404 (这是/ location将做的可疑的事情)。
让我们来加密SSL证书吧,因为我可以提供静态内容(通过301状态将http请求从80重定向到443 )。
我的nginx默认配置如下所示:
# HTTP - redirect all requests to HTTPS
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
return 301 https://$host$request_uri;
}
# HTTPS - serve HTML from /usr/share/nginx/html, proxy requests to /parse/
# through to Parse Server
server {
listen 443;
server_name example.com;
root /usr/share/nginx/html;
index index.html index.htm;
ssl on;
# Use certificate and key provided by Let's Encrypt:
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
# Pass requests for /parse/ to Parse Server instance at localhost:1337
location /parse/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:1337/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_redirect off;
}
location / {
try_files $uri $uri/ =404;
}
}
这是nginx access.log中的一个典型行:
xxx.xxx.xxx.xxx - - [20/Mar/2016:18:54:53 -0400] "PUT /parse/classes/_User/xxxxxxxxxx HTTP/1.1" 404 68 "-" ...
有什么方法可以打开更详细的调试,这样我就可以知道为什么匹配失败了吗?
谢谢,彼得
解决方案(见下文)注:在proxy_pass配置上添加/解析/
location /parse/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:1337/parse/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_redirect off;
}
发布于 2016-03-21 09:36:33
您的配置不代理https://example.com/parse
,而是代理https://example.com/parse/
。前一个URI由location /
块处理。
而且,URI https://example.com/parse/
被发送到上游的http://example.com:1337/
,而不是http://example.com:1337/parse
。
如果您需要透明地代理URI而不需要尾随/
,请使用:
location /parse {
proxy_pass http://localhost:1337;
...
}
注意,两个尾随的/
已被删除。详情请参见本文件。
https://stackoverflow.com/questions/36120467
复制相似问题