【发布时间】:2021-01-17 21:15:22
【问题描述】:
我正在构建一个现在在 localhost 上运行的应用程序。我在 https://localhost/ 上启动并运行了整个 dockerized 应用程序。 HTTP 请求被重定向到 HTTPS
我在 docker-compose.yml 中的 nginx 配置正在处理所有应有的请求。
我希望我的应用程序可以从任何地方访问,因此我尝试使用 Ngrok 将请求路由到我的本地主机。实际上我有一个正在开发的移动应用程序,所以需要一个本地服务器用于 api。
现在,当我在浏览器中输入 ngrok 的 url,如 abc123.ngrok.io 时,nginx 会将其转换为 https://localhost/。这适用于我的主机系统的浏览器,因为我的网络应用程序只在那里工作,但是当我在我的移动模拟器中打开它时。它不起作用。
我是 nginx 的新手。任何建议都将受到欢迎。 这是我的 nginx 配置。
nginx.conf
upstream web {
ip_hash;
server web:443;
}
# Redirect all HTTP requests to HTTPS
server {
listen 80;
server_name localhost;
return 301 https://$server_name$request_uri;
}
# for https requests
server {
# Pass request to the web container
location / {
proxy_pass https://web/;
}
location /static/ {
root /var/www/mysite/;
}
listen 443 ssl;
server_name localhost;
# SSL properties
# (http://nginx.org/en/docs/http/configuring_https_servers.html)
ssl_certificate /etc/nginx/conf.d/certs/localhost.crt;
ssl_certificate_key /etc/nginx/conf.d/certs/localhost.key;
root /usr/share/nginx/html;
add_header Strict-Transport-Security "max-age=31536000" always;
}
这个配置是我从教程中得到的。
【问题讨论】:
标签: django nginx networking server ngrok