然后我pull了一份php7-fpm的镜像到一个新容器里,并启动映射端口9000:9000,
请问如何才能让宿主机的nginx和容器里的php关联起来呢?望解答谢谢。
10.07
我访问外网ip然后进入的是docker容器里的www根目录(默认是 /var/www/html)
我宿主机的nginx配置如下:
······· location / { root /var/www/xx; #宿主机的web应用所在目录 index index.html index.php; } ······· location ~ \.php$ { root /var/www/xx; #宿主机的web应用所在目录 fastcgi_pass 192.168.42.18:9000; #docker容器php-fpm分配的内网ip和端口 fastcgi_index index.php; fastcgi_param script_filename /var/www/html/$fastcgi_script_name; # /var/www/html 是php容器的页面存放目录 include /usr/local/nginx/conf/fastcgi_params; #宿主机nginx所在目录 }
请问如何让外网访问 /var/www/xx 这个目录呢
回复内容: 我的宿主机部署了nginx,并启动映射到80端口,
然后我pull了一份php7-fpm的镜像到一个新容器里,并启动映射端口9000:9000,
请问如何才能让宿主机的nginx和容器里的php关联起来呢?望解答谢谢。
10.07
我访问外网ip然后进入的是docker容器里的www根目录(默认是 /var/www/html)
我宿主机的nginx配置如下:
······· location / { root /var/www/xx; #宿主机的web应用所在目录 index index.html index.php; } ······· location ~ \.php$ { root /var/www/xx; #宿主机的web应用所在目录 fastcgi_pass 192.168.42.18:9000; #docker容器php-fpm分配的内网ip和端口 fastcgi_index index.php; fastcgi_param script_filename /var/www/html/$fastcgi_script_name; # /var/www/html 是php容器的页面存放目录 include /usr/local/nginx/conf/fastcgi_params; #宿主机nginx所在目录 }
请问如何让外网访问 /var/www/xx 这个目录呢
首先,容器间连接使用的是--link参数,而不是通过ip,也不是通过-p映射端口。
其次,nginx搭配php的最佳实际是,两个容器挂载相同的数据卷(也就是代码目录)。
建议先熟悉一下docker的基础使用方法。
https://docs.docker.com/
你的配置中:
fastcgi_param script_filename /var/www/html/$fastcgi_script_name;
改成:
fastcgi_param script_filename /var/www/xx/$fastcgi_script_name;
试试;
直接访问nginx就能访问到,nginx会转发请求。
