我注意到docker nginx存在问题,当nginx在主机(apt-get install
)上运行时并非如此。以下是如何重现我的问题:
docker stop $(docker ps -aq)
docker rm $(docker ps -aq)
容器1上的docker run -ti --name agitated_stallman ubuntu:14.04 bash
nc -l 4545
容器2上的LOLPATH=$HOME/testdocker
echo $LOLPATH
mkdir -p $LOLPATH
cd $LOLPATH
subl mple.conf
server {
listen 80;
root /var/www/html;
location /roz {
proxy_pass http://neocontainer:4545;
proxy_set_header Host $host;
}
}
docker run --link agitated_stallman:neocontainer -v $LOLPATH/mple.conf:/etc/nginx/sites-available/default -p 12345:80 nginx:1.9
主机上的sudo apt-get install curl
curl http://localhost:12345/roz
来自'nginx'的错误响应:
2016/03/04 19:59:18 [error] 8#8: *3 open() "/usr/share/nginx/html/roz" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /roz HTTP/1.1", host: "localhost:12345"
172.17.0.1 - - [04/Mar/2016:19:59:18 +0000] "GET /roz HTTP/1.1" 404 169 "-" "curl/7.45.0" "-"
sudo apt-get install nginx
sudo subl /etc/nginx/sites-available/default
。
server {
listen 80;
root /var/www/html;
location /roz {
proxy_pass http://localhost:4646;
proxy_set_header Host $host;
}
}
sudo service nginx restart
主机上的nc -l 4646
主机上的sudo apt-get install curl
curl http://localhost:80/roz
来自'nc'的成功响应:
GET /roz HTTP/1.0
Host: localhost
Connection: close
User-Agent: curl/7.45.0
Accept: */*
答案 0 :(得分:1)
简而言之:使用-v $LOLPATH/mple.conf:/etc/nginx/conf.d/default.conf
nginx:1.9
docker image currently uses nginx包,而不是官方的debian存储库。如果您检查that package,您会发现/etc/nginx/nginx.conf
仅include
/etc/nginx/conf.d/*.conf
/etc/nginx/conf.d/default.conf
,并且该套餐附带预先包含的server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
# other not important stuff
# ...
}
:
open() "/usr/share/nginx/html/roz" failed
因此根本不使用您的配置,这解释了include /etc/nginx/sites-available/*
错误。
当您在主机上直接安装nginx时,您可能会使用官方debian存储库,该存储库具有不同的主配置文件,而后者又会pizze.n
,并且实际使用了您的配置。