Nginx Docker无法通过server_name访问服务器

我有我的Nginxconfiguration的问题,我不能设置我的server_name。 我试图build立我的docker容器与Nginxconfiguration里面。

我的Dockerfile身体。

 FROM nginx RUN rm -rf /etc/nginx/conf.d/* RUN mkdir /etc/nginx/ssl RUN chown -R root:root /etc/nginx/ssl RUN chmod -R 600 /etc/nginx/ssl COPY etc/ssl/certs/qwobbleprod.crt /etc/nginx/ssl COPY etc/ssl/certs/app.qwobble.com.key /etc/nginx/ssl COPY nginx/default.conf /etc/nginx/conf.d/ COPY dist /usr/share/nginx/html EXPOSE 443 

和我的Nginxconfiguration文件 – >

 server { listen 443 ssl default_server; root /usr/share/nginx/html; server_name blabla.com www.blabla.com; access_log /var/log/nginx/nginx.access.log; error_log /var/log/nginx/nginx.error.log; ssl on; ssl_certificate /etc/nginx/ssl/blabla.crt; ssl_certificate_key /etc/nginx/ssl/blabla.com.key; sendfile on; location / { try_files $uri /index.html =404; } location ~* \.(js|css|png|jpg|jpeg|gif|ico|html)$ { expires max; log_not_found off; } } 

我试图build立和运行我的docker集装箱

 docker build -t <name> . docker run -it -p 443:443 <name> 

因此,我有我的应用程序在https:// localhost:443,但我没有通过https://blabla.com:443或https://www.blabla.com:443访问我的应用程序

我是与DockerNginx合作的新手,我不知道什么是错的。 我会感激任何帮助!

在这种情况下,我希望你实际上需要blabla.com域,并且dns(域名服务)应该指向你的外部IP地址。

然后你必须configuration路由器接受端口443上的连接(你想要的),并把它指向(端口转发)到运行你实际运行的端口上的docker映像的计算机上。

在运行Docker的计算机上打开防火墙设置也可能是必要的。

我看到你也想听https,所以你可能需要一些证书。

或者如果你想伪造它,你可以编辑你的hosts文件(在Mac或Linux /etc/hosts )并添加一个条目,如:

 ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost 127.0.0.1 blabla.com 

但现在blabla.com只会在你的机器上工作…

希望能帮助到你