Skip to content

Commit 9c852e9

Browse files
committed
Update nginx reverse proxy config to avoid serving PHP files
1 parent 9211be0 commit 9c852e9

3 files changed

Lines changed: 59 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,31 @@ jobs:
110110
- run: docker logs $(docker ps -qn1)
111111
if: ${{ always() }}
112112

113-
nginx-webserver:
113+
nginx-reverse-proxy:
114+
name: nginx reverse proxy + X
115+
runs-on: ubuntu-22.04
116+
strategy:
117+
matrix:
118+
config:
119+
- nginx-reverse-proxy-public.conf
120+
steps:
121+
- uses: actions/checkout@v4
122+
- uses: shivammathur/setup-php@v2
123+
with:
124+
php-version: 8.3
125+
- run: composer install -d tests/integration/
126+
- run: docker build -f tests/integration/Dockerfile-basics tests/integration/
127+
- run: docker run -d -p 8080:8080 -v "$PWD/composer.json":/app/composer.json $(docker images -q | head -n1)
128+
- run: docker run -d --net=host -v "$PWD/tests/integration/":/home/framework-x/ -v "$PWD"/tests/integration/${{ matrix.config }}:/etc/nginx/conf.d/default.conf nginx:stable-alpine
129+
- run: bash tests/await.sh http://localhost
130+
- run: bash tests/integration.bash http://localhost
131+
- run: docker stop $(docker ps -qn2)
132+
- run: docker logs $(docker ps -qn1)
133+
if: ${{ always() }}
134+
- run: docker logs $(docker ps -qn2 | tail -n1)
135+
if: ${{ always() }}
136+
137+
nginx-fpm:
114138
name: nginx + PHP-FPM (PHP ${{ matrix.php }})
115139
runs-on: ubuntu-22.04
116140
strategy:

docs/best-practices/deployment.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,24 @@ achieved by using an nginx configuration with the following contents:
423423

424424
```
425425
server {
426-
root /home/alice/projects/acme/public;
427-
index index.php index.html;
428-
426+
# Serve static files from `public/`, proxy dynamic requests to Framework X
429427
location / {
430-
try_files $uri $uri/ @x;
428+
location ~* \.php$ {
429+
try_files /dev/null @x;
430+
}
431+
root /home/alice/projects/acme/public;
432+
try_files $uri @x;
431433
}
432434
433435
location @x {
434436
proxy_pass http://localhost:8080;
437+
proxy_set_header Host $host;
438+
proxy_set_header Connection "";
439+
}
440+
441+
# Optional: handle Apache config with Framework X if it exists in `public/`
442+
location ~ \.htaccess$ {
443+
try_files /dev/null @x;
435444
}
436445
}
437446
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
server {
2+
# Serve static files from `public/`, proxy dynamic requests to Framework X
3+
location / {
4+
location ~* \.php$ {
5+
try_files /dev/null @x;
6+
}
7+
root /home/framework-x/public;
8+
try_files $uri @x;
9+
}
10+
11+
location @x {
12+
proxy_pass http://localhost:8080;
13+
proxy_set_header Host $host;
14+
proxy_set_header Connection "";
15+
}
16+
17+
# Optional: handle Apache config with Framework X if it exists in `public/`
18+
location ~ \.htaccess$ {
19+
try_files /dev/null @x;
20+
}
21+
}

0 commit comments

Comments
 (0)