Skip to content

Changes the behavior of Nginx when configured to serve static files #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 20, 2024
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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ Open `http://localhost:8000` to view it in the browser
Though probably not necessary in most cases, if you want to test/modify/emulate how this will run in production you can:

- In `.env` set:
```

```shell
DEBUG = 'False'
```

- Modify the app container's command in `docker-compose.yaml` to run:
```

```shell
gunicorn signal_documentation.wsgi:application --bind 0.0.0.0:8000"

*(Essentially you'll replace just the last line of the command, switching out the "runserver" line)
Expand All @@ -96,6 +99,10 @@ Open `http://localhost` to view it in the browser. In this usage your request wi

The primary use case for this will be when making changes to the Nginx container image that runs in production and hosts the static file content, or also if making changes to the Gunicorn config.

Additionally, though again not required for local development, you can also specify an env var of `MAIN_PAGE = $name`, and the app will be served at `http://localhost:8000/$name` (if running in debug mode), or if you've set `DEBUG = 'False'` to run it in Nginx/production mode at `http://localhost/$name/`. Note the ending slash when in Nginx/production mode _and_ using the `MAIN_PAGE` env var.

The primary use case is so that we have flexibility to serve the application at something other than the "bare" URL, though doing this is not necessary for local development.

Changes of this sort should be carefully evaluated as they may require interaction with systems managed by devops folks.

## [Django admin](https://docs.djangoproject.com/en/4.1/ref/contrib/admin/) web interface (user should be `is_staff` or `is_superuser`)
Expand Down
5 changes: 2 additions & 3 deletions nginx/default.conf.template
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
server {
listen 80;
server_name sdnginx;

location /static/ {
location ~* /static/(.*)$ {
autoindex on;
alias /staticfiles/;
alias /staticfiles/$1;
}

location / {
Expand Down
Loading