Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Provide a default nginx-app.conf #139

Merged
merged 2 commits into from
Aug 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions php-nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ RUN mkdir -p $APP_DIR $LOG_DIR $UPLOAD_DIR $SESSION_SAVE_PATH \

# Put config files into place.
COPY nginx.conf fastcgi_params gzip_params $NGINX_DIR/conf/
COPY nginx-app.conf $NGINX_USER_CONF_DIR
COPY php.ini $PHP56_DIR/lib/php.ini
COPY php.ini $PHP7_DIR/lib/php.ini
COPY php-fpm.conf $PHP56_DIR/etc/php-fpm.conf
Expand Down
33 changes: 20 additions & 13 deletions php-nginx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,35 @@ runtime_config:

## How to change nginx.config

Put `nginx-app.conf` file which includes piece of nginx configuration
for the `server` section in the project top directory. Then it will be
moved to an appropriate directory and included from the main nginx
configuration file.
An `nginx-app.conf` configuration file is included in the server
section of the main nginx configuration file. The default
configuration file looks like this:

Assumption is that you don't often need to entirely modify the
[default nginx file](nginx.conf).
There is an `include` directive in the `server` section and your
configuration file will be included there.
```ini
location / {
# try to serve files directly, fallback to the front controller
try_files $uri /index.php$is_args$args;
}
```

To define a custom configuration file, put a file named
`nginx-app.conf` in the project root directory. The runtime will
override the default file with the file you provided.

Here is an example configuration for silex.
By default, index.php is used as the framework front controller. You
may need to change this to something different for your project. The
Symfony framework, for instance, uses app.php instead of index.php.

nginx-app.conf:
Here is an example `nginx-app.conf` for the Symfony framework:

```ini
location / {
# try to serve file directly, fallback to front controller
try_files $uri /index.php$is_args$args;
# try to serve files directly, fallback to the front controller
try_files $uri /app.php$is_args$args;
}
```

I hope this mechanism can cover most of the web frameworks, but let us
I hope this mechanism can cover most of your use cases, but let us
know if you found otherwise.

## Change the PHP version
Expand Down
4 changes: 4 additions & 0 deletions php-nginx/nginx-app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
location / {
# try to serve files directly, fallback to the front controller
try_files $uri /index.php$is_args$args;
}
10 changes: 10 additions & 0 deletions tests/ServingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public function testIndex()
$this->assertContains('Hello World', $resp->getBody()->getContents());
}

public function testNonExistentPath()
{
// Non-existent paths should be served by the `index.php` too, thanks
// to the default nginx-app.conf.
$resp = $this->client->get('non-existent-path');
$this->assertEquals('200', $resp->getStatusCode(),
'non-existent-path status code');
$this->assertContains('Hello World', $resp->getBody()->getContents());
}

public function testPhpInfo()
{
// Access to phpinfo.php, while phpinfo() is disabled by default.
Expand Down