Skip to content

Instantly share code, notes, and snippets.

@varaskkar
Last active April 12, 2023 19:42
Show Gist options
  • Save varaskkar/a0dd7a1b7283d10cc976684f96fe7584 to your computer and use it in GitHub Desktop.
Save varaskkar/a0dd7a1b7283d10cc976684f96fe7584 to your computer and use it in GitHub Desktop.
Docker Compose: Nginx + PHP + SSL
server {
index index.php index.html;
server_name phpfpm.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
version: "3.3"
services:
web:
image: nginx:1.23.3-alpine
expose:
- "80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
environment:
- VIRTUAL_HOST=alarmsworld.com,www.alarmsworld.com
- LETSENCRYPT_HOST=alarmsworld.com,www.alarmsworld.com
- LETSENCRYPT_EMAIL=felipe@alarmsworld.com
depends_on:
- php-fpm
- nginx-proxy
- letsencrypt
php-fpm:
image: php:8-fpm
volumes:
- ./src:/var/www/html
nginx-proxy:
image: jwilder/nginx-proxy
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- certs:/etc/nginx/certs:ro
- vhostd:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
labels:
- com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
restart: always
environment:
- NGINX_PROXY_CONTAINER=nginx-proxy
volumes:
- certs:/etc/nginx/certs:rw
- html:/usr/share/nginx/html
- vhostd:/etc/nginx/vhost.d
- /var/run/docker.sock:/var/run/docker.sock:ro
volumes:
certs:
html:
vhostd:
@varaskkar
Copy link
Author

varaskkar commented Apr 12, 2023

Build this structure:

  • /myfolder/nginx/default.conf
  • /myfolder/src/index.php
  • /myfolder/docker-compose.yml

Steps:

  1. Buy a domain (GoDaddy, Google Domains, ...) and make it point to the public IP of your server
  2. On your server (AWS EC2, Azure, ...), build this file structure
  3. In docker-compose.yml change alarmsworld.com to your domain name (from GoDaddy, Google Domains, ...)
  4. Run docker-compose up -d in /myfolder path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment