【问题标题】:Docker nginx with ubuntu not working on a custom port带有ubuntu的Docker nginx不能在自定义端口上工作
【发布时间】:2019-12-30 20:42:17
【问题描述】:

我在我的 ubuntu nginx 配置中使用 docker 设置了以下内容,这是 nginx 配置

server {
listen 6090;
server_name mydomain.com;
location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
       proxy_set_header   Host $http_host;
       proxy_pass         http://127.0.0.1:6090;

 }

}

上述方法无法正常工作,但当我将侦听端口更改为 80 时,将 listen 6090 更改为 listen 80 它可以正常工作。我通过访问 url mydomain.com:6090

来访问它

但我想以mydomain.com:6090 的身份访问我的网址,我还需要做什么才能完成这项工作

上面的 mydomain.com 不是实际的 url。

更新这是我的 nginx docker 配置

webserver:
 image: nginx
 container_name: webserver
 restart: unless-stopped
 tty: true
 ports:
 - "80:80"
 - "443:443"

【问题讨论】:

  • 错误日志说什么?如果您的意思是 nginx 根本无法启动,请检查 /var/log/nginx/error.lognginx -t,否则请告诉我们您遇到的确切问题或解释您的意思 fails
  • 应用程序永远无法访问 nginx。它显示无法访问此站点。
  • 好吧,它正在尝试对自己做一个proxy_pass...

标签: docker nginx nginx-config


【解决方案1】:

您需要倾听并公开相同的 Ports 以使其正常工作:

nginx 配置:

listen 6090;

撰写:

 ports:
   - "6090:6090"

expose 端口 80 因此 listen 80 将工作......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-27
    • 2020-12-10
    • 2021-09-01
    • 2018-04-08
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多