Last active
April 7, 2023 01:33
-
-
Save Machy8/f7bd27b2e6b01dd9e057c2e90e5f49d3 to your computer and use it in GitHub Desktop.
PHP-FPM 7.1 with Unix Sockets + Nginx in Docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3" | |
services: | |
server: | |
container_name: my-server | |
working_dir: /var/www/html | |
build: ./server | |
volumes: | |
- ./:/var/www/html:delegated | |
- ./server/log:/var/log/nginx | |
- ./server/nginx.conf:/etc/nginx/nginx.conf | |
- ./server/vhost.conf:/etc/nginx/sites-enabled/default.conf | |
expose: | |
- "80" | |
- "443" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM debian:stretch | |
RUN apt-get update && apt-get install -y --no-install-recommends \ | |
curl \ | |
wget \ | |
zip \ | |
git \ | |
unzip && \ | |
rm -rf /var/lib/apt/lists/* && \ | |
apt-get clean | |
# Install nginx | |
RUN apt-get update && apt-get -y install nginx && \ | |
echo "\ndaemon off;" >> /etc/nginx/nginx.conf && \ | |
rm -rf /etc/nginx/sites-enabled/* | |
# Install PHP | |
RUN apt-get install -y apt-transport-https lsb-release ca-certificates && \ | |
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg && \ | |
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list && \ | |
apt-get update && \ | |
apt-get install -y \ | |
php7.1 \ | |
php7.1-fpm | |
EXPOSE 80 443 | |
CMD service php7.1-fpm start && nginx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user www-data; | |
worker_processes 4; | |
pid /run/nginx.pid; | |
daemon off; | |
events { | |
worker_connections 768; | |
} | |
http { | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
keepalive_timeout 65; | |
types_hash_max_size 2048; | |
include /etc/nginx/mime.types; | |
access_log /var/log/nginx/access.log; | |
error_log /var/log/nginx/error.log; | |
gzip on; | |
gzip_disable "msie6"; | |
gzip_comp_level 5; | |
gzip_min_length 256; | |
gzip_proxied any; | |
gzip_vary on; | |
gzip_types | |
application/atom+xml | |
application/javascript | |
application/json | |
application/ld+json | |
application/manifest+json | |
application/rss+xml | |
application/vnd.geo+json | |
application/vnd.ms-fontobject | |
application/x-font-ttf | |
application/x-web-app-manifest+json | |
application/xhtml+xml | |
application/xml | |
font/opentype | |
image/bmp | |
image/svg+xml | |
image/x-icon | |
text/cache-manifest | |
text/css | |
text/plain | |
text/vcard | |
text/vnd.rim.location.xloc | |
text/vtt | |
text/x-component | |
text/x-cross-domain-policy; | |
## | |
# Virtual Host Configs | |
## | |
include /etc/nginx/sites-enabled/*; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
root /var/www/html/www; | |
index index.php; | |
location ~ /\.(ht|gitignore) { # deny access to .htaccess files, if Apache's document root concurs with nginx's one | |
deny all; | |
} | |
location ~ \.(neon|ini|log|yml)$ { # deny access to configuration files | |
deny all; | |
} | |
location ~ /.well-known { | |
allow all; | |
} | |
location ~* \.(?:manifest|appcache|html?|xml|json)$ { | |
expires -1; | |
} | |
# Feed | |
location ~* \.(?:rss|atom)$ { | |
expires 1h; | |
add_header Cache-Control "public"; | |
} | |
# Media: images, icons, video, audio, HTC | |
location ~* \.(?:jpg|webp|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { | |
expires 1M; | |
access_log off; | |
add_header Cache-Control "public"; | |
} | |
# CSS and Javascript | |
location ~* \.(?:css|js)$ { | |
expires 1y; | |
access_log off; | |
add_header Cache-Control "public"; | |
} | |
location / { | |
try_files $uri $uri/ index.php?$args; | |
} | |
location ~ \.php$ { | |
include fastcgi_params; | |
fastcgi_pass unix:/run/php/php7.1-fpm.sock; | |
fastcgi_index $document_root/index.php; | |
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; | |
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; | |
fastcgi_param PATH_TRANSLATED $document_root/$fastcgi_path_info; | |
fastcgi_param PATH_INFO $fastcgi_path_info; | |
fastcgi_read_timeout 300; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment