[英]Nginx Docker haven't access to server through server_name
我的Nginx
配置有問題,我無法設置我的server_name。 我試圖用Nginx
配置構建我的Docker容器。
我的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
和我的Nginx
配置文件->
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;
}
}
我試圖構建並運行我的Docker容器
docker build -t <name> .
docker run -it -p 443:443 <name>
結果,我的應用程序位於https:// localhost:443上,但無法通過https://blabla.com:443或https://www.blabla.com:443訪問我的應用程序
我是使用Docker
和Nginx
的新手,我不知道出什么問題了。 我將不勝感激!
在這種情況下,我希望您實際上需要blabla.com域,並且dns(域名服務)應該指向您的外部IP地址。
然后,您必須將路由器配置為接受端口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只能在您的計算機上運行...
希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.