Created
March 7, 2025 22:13
-
-
Save SamuelDavis/008ddfa7e46a04f2bae4c82b0dc7f80a to your computer and use it in GitHub Desktop.
Dockerize many PHP Sites with HTTPS
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
services: | |
nginx: | |
image: nginx:alpine | |
container_name: web | |
depends_on: | |
- php | |
ports: | |
- "80:80" | |
- "443:443" | |
volumes: | |
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro | |
- ./nginx-common.conf:/etc/nginx/nginx-common.conf:ro | |
- ./certs:/etc/nginx/certs:ro | |
- ./sites:/var/www/html | |
php: | |
image: php | |
container_name: app | |
working_dir: /var/www/html | |
ports: | |
- "8080:80" | |
- "8443:443" | |
volumes: | |
- ./sites:/var/www/html | |
composer: | |
image: composer | |
container_name: composer | |
working_dir: /var/www/html | |
volumes: | |
- ./sites:/var/www/html | |
- ./.composer:/tmp/.composer | |
environment: | |
COMPOSER_CACHE_DIR: /tmp/.composer |
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
listen 80; | |
listen 443 ssl; | |
ssl_certificate /etc/nginx/certs/cert.pem; | |
ssl_certificate_key /etc/nginx/certs/key.pem; | |
if ($scheme = http) { | |
return 301 https://$host$request_uri; | |
} | |
index index.php index.html index.htm; | |
location / { | |
try_files $uri $uri/ /index.php?$query_string; | |
} | |
location ~ \.php$ { | |
fastcgi_pass php:9000; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} |
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 { | |
server_name site1.localhost *.site1.localhost; | |
root /var/www/html/site1/public; | |
include /etc/nginx/nginx-common.conf; | |
} | |
server { | |
server_name site2.localhost *.site2.localhost; | |
root /var/www/html/site2/public; | |
include /etc/nginx/nginx-common.conf; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment