Skip to content

Instantly share code, notes, and snippets.

@maitrungduc1410
Created November 4, 2020 03:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maitrungduc1410/355bbe155b7c92fd0357690a6e793255 to your computer and use it in GitHub Desktop.
Save maitrungduc1410/355bbe155b7c92fd0357690a6e793255 to your computer and use it in GitHub Desktop.
Docker PHP Nginx without mouting source code to Nginx
version: '3.4'
services:
app:
image: php:7.2-fpm-alpine
restart: unless-stopped
volumes:
- ./:/var/www/html
- ./www.conf:/usr/local/etc/php-fpm.d/www.conf
webserver:
image: nginx:1.17-alpine
restart: unless-stopped
ports:
- "8000:80"
volumes:
# - ./:/var/www/html
- ./nginx.conf:/etc/nginx/conf.d/default.conf
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_hide_header X-Powered-By;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ^~ /css {
add_header Content-Type text/css;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_hide_header X-Powered-By;
}
location ^~ /js {
add_header Content-Type application/javascript;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_hide_header X-Powered-By;
}
}
[www]
user = www-data
group = www-data
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
security.limit_extensions = .php .php3 .php4 .php5 .php7 .css .js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment