NGINX and URL Path Configuration for eventyay
This document outlines the NGINX and URL path setup for the eventyay project hosted at https://github.com/fossasia/eventyay. This Django project utilizes FORCE_SCRIPT_NAME to configure a base path, allowing the application to run on a specified sub-path within the domain.
Project Setup in Django
In eventyay, the following settings are used to configure the base path for the application:
# Django Settings
BASE_PATH = config.get('Eventyay', 'base_path', fallback='/tickets')
FORCE_SCRIPT_NAME = BASE_PATH
BASE_PATH: Retrieved from the
eventyay.cfgconfiguration file, which allows flexible configuration of the base URL path. By default, this is set to'/tickets'.FORCE_SCRIPT_NAME: Uses the value from
BASE_PATH, setting/ticketsas the base path for URL routing within Django.
This means that all URLs within Django are prefixed with /tickets, allowing users to access eventyay via URLs like domain.com/tickets/.
NGINX Configuration
The following NGINX configuration serves the eventyay application along with other services such as talk and video. The configuration is hosted on server.
Key Sections of NGINX Configuration
Server Block for HTTPS: This block listens on port
443for HTTPS traffic. SSL certificates are configured here using Let’s Encrypt for secure communication.server { server_name your-domain; listen 443 ssl; ssl_certificate /etc/../fullchain.pem; ssl_certificate_key /etc/../privkey.pem; include /etc/../options-ssl-nginx.conf; ssl_dhparam /etc/../ssl-dhparams.pem; }
URL Path Configurations:
Root Location: - Proxies requests from
https://your-domain/to the backend onlocalhost:8455/common/./tickets: - This location is for the
eventyayapplication. - Requests tohttps://your-domain/tickets/are proxied tolocalhost:8455/.location /tickets/ { proxy_pass http://localhost:8455/; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host; }
/talk and /video: - These locations handle other components (
talkandvideo) by proxying requests to their respective backend services on different ports.
Custom Redirects:
/video/admin: Redirects requests from
/video/admin/to thecontrolpanel athttps://your-domain:8443/control.
location /video/admin/ { return 301 https://your-domain:8443/control; }
/talk/static and /media: - Routes static files for the
talkcomponent, setting up paths for/talk/media/and/media/to point to Docker volumes where media files are stored.location /talk/media/ { rewrite ^/talk/media/(.*)$ /media/$1 break; root /var/lib/docker/volumes/eventyay_talk-data/_data; }
HTTP to HTTPS Redirection: - Redirects all HTTP requests on port
80to HTTPS, ensuring secure communication.server { listen 80; server_name your-domain; if ($host = your-domain) { return 301 https://$host$request_uri; } return 404; }
Secondary HTTPS Server Block on Port 8443: - A separate server block listens on port
8443for HTTPS traffic and proxies requests to the backend service running on port8375.server { listen 8443 ssl; server_name your-domain; ssl_certificate /etc/../fullchain.pem; ssl_certificate_key /etc/../privkey.pem; include /etc/../options-ssl-nginx.conf; ssl_dhparam /etc/../ssl-dhparams.pem; location / { proxy_pass http://localhost:8375/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Host $http_host; } }
Accessing eventyay
With this setup:
The URL for accessing the
eventyayapplication control panel ishttps://your-domain/tickets/control.NGINX routes requests to the correct backend ports based on path prefixes, ensuring that each application (tickets, talk, video) is isolated within its respective path.
Summary
This configuration leverages FORCE_SCRIPT_NAME in Django to set /tickets as the base path, while NGINX routes requests to various services based on URL path prefixes. This setup provides a secure and organized way to access different components on the same domain.