Skip to content

Commit

Permalink
chore: migrate from apache to nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-chinour committed Dec 10, 2023
1 parent fa8f28e commit a279684
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 70 deletions.
21 changes: 21 additions & 0 deletions .heroku/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add Cache-Control header on js/css files
location ~* .(?:css|js)$ {
expires 1y;
add_header Cache-Control "public, max-age=60 s-maxage=3600";
}

location / {
# try to serve file directly, fallback to rewrite
try_files $uri @rewriteapp;
}

location @rewriteapp {
# rewrite all to index.php
rewrite ^(.*)$ /index.php/$1 last;
}

location ~ ^/index\.php(/|$) {
try_files @heroku-fcgi @heroku-fcgi;
# ensure that /index.php isn't accessible directly, but only through a rewrite
internal;
}
20 changes: 20 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3.4'

services:
web:
container_name: blog.nginx
image: nginx:latest
ports: [ "8080:80" ]
volumes:
- ".:/var/www/html:ro"
- "./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf"
depends_on: [ app ]
links: [ app ]

app:
container_name: blog.app
build:
context: .
dockerfile: ./docker/Dockerfile
target: app
volumes: [ ".:/var/www/html" ]
13 changes: 0 additions & 13 deletions docker-compose.yml

This file was deleted.

6 changes: 1 addition & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
FROM php:8.2-apache AS app
FROM php:8.2-fpm-alpine AS app

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/

RUN install-php-extensions gd zip opcache intl
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

RUN a2enmod headers
COPY docker/apache2/default.conf /etc/apache2/sites-available/000-default.conf
COPY docker/apache2/mods-enabled/headers.conf /etc/apache2/mods-enabled/headers.conf

WORKDIR /var/www
20 changes: 0 additions & 20 deletions docker/apache2/default.conf

This file was deleted.

5 changes: 0 additions & 5 deletions docker/apache2/mods-enabled/headers.conf

This file was deleted.

30 changes: 30 additions & 0 deletions docker/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
server {
root /var/www/html/public;

location ~* .(?:css|js)$ {
expires 1y;
add_header Cache-Control "public, max-age=60 s-maxage=3600";
}

location / {
try_files $uri /index.php$is_args$args;
}

location ~ ^/index\.php(/|$) {
fastcgi_pass app:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;

fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;

internal;
}

location ~ \.php$ {
return 404;
}

error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
27 changes: 0 additions & 27 deletions public/.htaccess

This file was deleted.

0 comments on commit a279684

Please sign in to comment.