Home > Backend Development > PHP Tutorial > How is the host's nginx related to the php in the docker container?

How is the host's nginx related to the php in the docker container?

WBOY
Release: 2016-10-10 11:55:56
Original
3018 people have browsed it

My host deployed nginx and started mapping to port 80,
Then I pulled an image of php7-fpm into a new container and started mapping port 9000:9000,

How can I associate nginx on the host with php in the container? Thank you for the answer.


10.07
I accessed the external IP and entered the www root directory in the docker container (default is /var/www/html)
The nginx configuration of my host machine is as follows:

<code>        ······· 
        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所在目录
        }
        </code>
Copy after login
Copy after login

How can I allow external networks to access the directory /var/www/XX?

Reply content:

My host deployed nginx and started mapping to port 80,

Then I pulled an image of php7-fpm into a new container and started mapping port 9000:9000,

How can I associate nginx on the host with php in the container? Thank you for the answer.


10.07I accessed the external IP and entered the www root directory in the
docker container (default is /var/www/html)The nginx configuration of my host machine is as follows:

<code>        ······· 
        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所在目录
        }
        </code>
Copy after login
Copy after login
How can I allow external networks to access the directory

/var/www/XX?

First of all, the connection between containers uses the --link parameter, not through IP, nor through -p mapping port.

Secondly, the best practice for using Nginx with PHP is that both containers mount the same data volume (that is, the code directory).


It is recommended to familiarize yourself with the basic usage of Docker first.

https://docs.docker.com/


In your configuration:

<code>fastcgi_param  SCRIPT_FILENAME  /var/www/html/$fastcgi_script_name;
</code>
Copy after login

Change to:

<code>fastcgi_param  SCRIPT_FILENAME  /var/www/XX/$fastcgi_script_name;</code>
Copy after login

Try it;

You can access it by accessing nginx directly, and nginx will forward the request.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template