Skip to content

Instantly share code, notes, and snippets.

@sagar290
Forked from Machy8/Dockerfile
Created February 18, 2022 14:48
Show Gist options
  • Save sagar290/8b5af9b8af0869eb45b0e289acb6ed71 to your computer and use it in GitHub Desktop.
Save sagar290/8b5af9b8af0869eb45b0e289acb6ed71 to your computer and use it in GitHub Desktop.
PHP-FPM 7.1 with Unix Sockets + Nginx in Docker
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"
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
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/*;
}
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