我使用PHP创建了nginx服务器,但它无法正常工作。
这是我的docker-compose.yml:
web:
image: nginx:latest
ports:
- 127.0.0.1:8080:80
volumes:
- ./docs:/docs
- ./site.conf:/etc/nginx/conf.d/site.conf
links:
- php
php:
image: php:latest
volumes:
- ./docs:/docs
site.conf:
server {
listen 80;
index index.php;
server_name php.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /docs;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
的/ etc /主机
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 php.local
Docker在终端中运行且没有错误:
sudo docker-compose up -d
Starting php_php_1
Starting php_web_1
当我输入浏览器127:0:0:1:8080或php.local:8080时,它拒绝连接为什么?
答案 0 :(得分:0)
这不是端口转发的正确语法
- 127.0.0.1:8080:80
用简单的
替换它 - 8080:80
docker-composer IP不是您的本地主机。要查找您的docker-compose IP,您需要致电docker-machine ip default
,(例如,如果您起诉OSX)...在此处阅读更多https://docs.docker.com/machine/reference/ip/
通常IP类似192.168.99.100
,所以如果你调用http://192.168.99.100:8080,你的docker-compose容器上的服务器应该是可以访问的