>  기사  >  개발 도구  >  docker-composer는 nginx+php 환경을 신속하게 구축합니다.

docker-composer는 nginx+php 환경을 신속하게 구축합니다.

藏色散人
藏色散人앞으로
2022-01-18 16:09:563501검색

이 글은 composer튜토리얼 칼럼에서 docker-composer를 사용하여 간단한 nginx+php 환경을 구축하는 방법을 소개하는 글입니다. 도움이 필요한 친구들에게 도움이 되길 바랍니다!

디렉터리 구조

➜  Study tree
├── conf
├── docker-compose.yaml
├── nginx
│   ├── conf
│   │   └── laravel.conf
│   └── html
│       └── index.php

index.php

<?php
/**
 * Created by OrangBus
 * User email: orangbus40400@gmail.com
 * website: orangbus.cn
 * blog: doc.orangbus.cn
 * github: github.com/orangbus
 */echo phpinfo();

nginx.conf

server {
 listen       80;
 server_name  localhost;

 location / {
 root   /usr/share/nginx/html;
 index  index.html index.htm index.php;
 }

 error_page   500 502 503 504  /50x.html;
 location = /50x.html {
 root   /usr/share/nginx/html;
 }

 location ~ \.php$ {
 fastcgi_pass   php8:9000;
 fastcgi_index  index.php;
 fastcgi_param  SCRIPT_FILENAME  /html$fastcgi_script_name;
 include        fastcgi_params;
 }}

주요 사항

fastcgi_pass   php8:9000;

php8: 여러 PHP 버전을 구성하려는 경우 PHP 컨테이너의 이름, 그냥 필요합니다. PHP 구성을 복사하고 해당 PHP 컨테이너 이름을 입력하세요

 php8: # php的容器名称
 image: php:8.0-fpm
 restart: always
 volumes:
 - ./nginx/html:/html--------------------------------
 php74: # 对应的nginx配置文件为:fastcgi_pass   php74:9000;
 image: php:8.0-fpm
 restart: always
 volumes:
 - ./nginx/html:/html
fastcgi_param  SCRIPT_FILENAME  /html$fastcgi_script_name;

/html: PHP 프로젝트는 [php 컨테이너 디렉터리](빨간색)

docker-compose

version: '3.5'services:
 nginx:
 image: nginx:latest restart: always ports:
 - 8010:80
 volumes:
 - ./nginx/html/:/usr/share/nginx/html # 注意点一
 - ./nginx/conf/:/etc/nginx/conf.d/ links:
 - php8 php8:
 image: php:8.0-fpm restart: always volumes:
 - ./nginx/html:/html #注意点二

에 매핑됩니다. 포인트 :

./nginx/html: 이 머신의 PHP 프로젝트 주소

/usr/share/nginx/html: nginx 기본 액세스 주소

참고 2:

./nginx/html : 로컬 PHP 프로젝트 주소

/html: 여기에 있는 주소는 로컬 PHP 코드를 PHP 컨테이너에 매핑합니다. 일반적으로 nginx 구성(빨간색)과 동일한 주소입니다. 팁: 간의 관계에 주의하세요. 이렇게 하면 간단한 nginx+php 관련 환경이 성공적으로 구성됩니다.

함정 방지 가이드:

를 사용하는 경우 컨테이너에 연결된 사용자 지정 포트는 유효하지 않습니다(예:

version: '3.5'services:
 php8:
 image: php:8.0-fpm restart: always volumes:
 - ./nginx/html:/html links: # 如果使用 links ,当我们php程序中填写mysql端口的时候应该是 3306 而不是 3307,但是我们外部是需要用3307端口去连接mysql的
 - mysql mysql:
 image: mysql:latest ports:
 - 3307:3306
).

위 내용은 docker-composer는 nginx+php 환경을 신속하게 구축합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 learnku.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제