【发布时间】:2020-04-07 13:43:34
【问题描述】:
我正在尝试浏览 nginx 和反向代理传递的杂草,而我感到困惑的一个领域是端口映射。这是一个示例 nginx 配置文件:
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name www.domain.com;
passenger_enabled on;
root /home/ubuntu/app/public;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
}
我在这里指定的是我的应用程序应该监听端口 443,因为它上面有一个自签名证书。它不接受端口 80 http,但只接受 443。这是我找到的关于 proxy_passing 到 localhost 的示例。这就是我想要做的。示例如下:
server {
listen 443;
server_name localhost;
ssl on;
ssl_certificate server.crt;
ssl_certificate_key server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://localhost:3000;
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-Client-Verify SUCCESS;
proxy_set_header X-Client-DN $ssl_client_s_dn;
proxy_set_header X-SSL-Subject $ssl_client_s_dn;
proxy_set_header X-SSL-Issuer $ssl_client_i_dn;
proxy_read_timeout 1800;
proxy_connect_timeout 1800;
}
}
这是我不明白的地方,可以澄清一下。在第二个示例中,我在听什么端口/url?在服务器块中,我看到了这个:
listen 443;
server_name localhost;
这意味着我们正在通过 https 在 443 上收听 localhost。到目前为止,这很简单,可以理解。现在我们到了location 块。
location / {
proxy_pass http://localhost:3000;
这里发生了什么?如果我启动 nginx 并在地址栏中输入 http:localhost:3000 会发生什么?它会因为我输入http 而失败吗?不应该是https:localhost:3000吗?我在监听端口 80、443 还是 3000?
另外,关于一个小问题。如果我打开我的 Postman 应用程序并使用第二个配置向http://localhost:3000 或https://localhost 键入获取请求会发生什么?它会访问 nginx 服务器还是尝试访问我笔记本电脑的 localhost?
【问题讨论】:
标签: django http nginx webserver