SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Downloaden Sie, um offline zu lesen
Multiple Django
applications on a single
server with nginx
PyGRAZ November 2021
Thomas Aglassinger v1.1
Goals
●
A Django application runs on a Ubuntu 20 LTS.
●
The application automatically starts on reboot.
●
The application can be controlled with systemctl.
●
Web content is served using the lightweight nginx server
(no Apache2 bloat).
●
The application uses HTTPS with its own (free) certificate.
●
Multiple applications can run on the same physical server.
Advantages
Pros
●
Works with Ubuntu 20 LTS
standard packages
●
Minimal intrusion
●
Minimal resource overhead
●
Transparent and relatively
easy to understand
Cons
●
You need to build something
for deployment yourself
(script with ssh/scp, git
pull, ...)
●
Doesn’t make you feel as
powerful as container
orchestration approaches.
Example
We want a Django application that:
●
Has the application code stored in
/var/www/<environment>/example/ with <environment> being
test, stage, production, ...
●
Can be accessed using the domain www.example.com
●
Uses HTTPS with its own free certificate
●
Redirects HTTP to HTTPS
Install required packages
●
Upgrade to current packages:
sudo apt-get -y upgrade
●
Install nginx, python3 and certbot:
sudo apt-get -y install certbot python3-certbot-nginx
(Note: The dependencies ensure that nginx and python3 are
installed with this automatically.)
Setup additional directories
●
Assumption: For now, we want to setup the example application in
the test environment.
→ The application will reside in /var/www/test/example/
●
For a simple installation, you can choose to serve static and media
files via nginx → Create the required directories:
sudo mkdir -p "/var/www/test/example/media"
sudo mkdir -p "/var/www/test/example/static"
Install your Django application
●
Copy your code to /var/www/test/example/
●
Set up a virtual environment using whatever venv tool is in fashion,
for example:
sudo apt-get -y install python3-venv
cd /var/www/test/example/
sudo python3 -m venv venv
. venv/bin/activate
●
Install dependent python packages, including gunicorn
Service architecture
nginx gunicorn
Django
application
Socket WSGI
●
WSGI: “Web Server Gateway Interface”, to forward requests to web services written in
Python
●
gunicorn: Python WSGI HTTP Server for UNIX; “simply implemented, light on server
resources, and fairly speedy”
/etc/systemd/system/example.socket
[Unit]
Description=gunicorn socket for example
[Socket]
ListenStream=/run/example.sock
[Install]
WantedBy=sockets.target
/etc/systemd/system/example.service
[Unit]
Description=gunicorn daemon for example
Requires=example.socket
After=network.target
[Service]
User=www-data
Group=www-data
WorkingDirectory=/var/www/test/example
ExecStart=/var/www/test/example/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/example.sock example.wsgi:application
[Install]
WantedBy=multi-user.target
/etc/systemd/system/example.service
[Unit]
Description=gunicorn daemon for example
Requires=example.socket
After=network.target
[Service]
User=www-data
Group=www-data
WorkingDirectory=/var/www/test/example
ExecStart=/var/www/test/example/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/example.sock example.wsgi:application
[Install]
WantedBy=multi-user.target
Change to as many
processes as needed.
Standard user
for web service
Wait for socket
service from before.
gunicorn in venv
from before
/etc/nginx/sites-available/www.example.com
server {
listen 80;
server_name www.example.com;
location = /favicon.ico {
access_log off;
log_not_found off;
}
location /static/ {
root /var/www/test/example;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/example.sock;
}
}
/etc/nginx/sites-available/www.example.com
server {
listen 80;
server_name www.example.com;
location = /favicon.ico {
access_log off;
log_not_found off;
}
location /static/ {
root /var/www/test/example;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/example.sock;
}
} socket service
from before.
Our domain
For now, use
plain HTTP
Serve static files
Activate nginx configuration
●
Activation is done by linking the enabled configuration to the
available one:
sudo ln -s /etc/nginx/sites-available/www.example.com
/etc/nginx/sites-enabled
●
Because this is a link and not a copy, changes in the available
configuration also reflect on the enabled one.
●
After changes restart nginx:
sudo systemctl restart nginx
Common tasks
●
Restart the service (e.g. after deployment)
sudo systemctl daemon-reload
sudo systemctl restart example
●
Analyze possible errors when starting the application:
sudo journalctl -u example
●
Analyze log files:
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/nginx/access.log
Easy mode for most files
●
nubops from https://github.com/roskakori/nubops
(from gamer slang: nub → noob → newbie)
●
Generate most of the files by running:
sudo nubops nginx-django test example www.example.com
●
Available on PyPI soon.
Enable HTTPS
●
sudo certbot --agree-tos -d www.example.com -n --nginx
Done!
●
Fairly lightweight infrastructure.
●
Few and small configurations file.
●
Well integrated into systemd.
●
Secure connections.
●
Transparent error tracking.

Weitere ähnliche Inhalte

Was ist angesagt?

Provisioning with Puppet
Provisioning with PuppetProvisioning with Puppet
Provisioning with Puppet
Joe Ray
 

Was ist angesagt? (20)

Learn basic ansible using docker
Learn basic ansible using dockerLearn basic ansible using docker
Learn basic ansible using docker
 
Infrastructure = Code
Infrastructure = CodeInfrastructure = Code
Infrastructure = Code
 
Ansible intro
Ansible introAnsible intro
Ansible intro
 
It Works On My Machine: Vagrant for Software Development
It Works On My Machine: Vagrant for Software DevelopmentIt Works On My Machine: Vagrant for Software Development
It Works On My Machine: Vagrant for Software Development
 
Improving WordPress Theme Development Workflow - Naveen Kharwar.
Improving WordPress Theme Development Workflow - Naveen Kharwar.Improving WordPress Theme Development Workflow - Naveen Kharwar.
Improving WordPress Theme Development Workflow - Naveen Kharwar.
 
Docker up and running
Docker up and runningDocker up and running
Docker up and running
 
Provisioning with Puppet
Provisioning with PuppetProvisioning with Puppet
Provisioning with Puppet
 
Ansible
AnsibleAnsible
Ansible
 
Puppet in the Pipeline
Puppet in the PipelinePuppet in the Pipeline
Puppet in the Pipeline
 
A quick intro to Ansible
A quick intro to AnsibleA quick intro to Ansible
A quick intro to Ansible
 
Sep Nasiri "Upwork PHP Architecture"
Sep Nasiri "Upwork PHP Architecture"Sep Nasiri "Upwork PHP Architecture"
Sep Nasiri "Upwork PHP Architecture"
 
Ansible introduction - XX Betabeers Galicia
Ansible introduction - XX Betabeers GaliciaAnsible introduction - XX Betabeers Galicia
Ansible introduction - XX Betabeers Galicia
 
Understanding Non Blocking I/O with Python
Understanding Non Blocking I/O with PythonUnderstanding Non Blocking I/O with Python
Understanding Non Blocking I/O with Python
 
Pragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecturePragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecture
 
Delivery Pipeline for Windows Machines
Delivery Pipeline for Windows MachinesDelivery Pipeline for Windows Machines
Delivery Pipeline for Windows Machines
 
Front-end tools
Front-end toolsFront-end tools
Front-end tools
 
Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!
 
Node4J: Running Node.js in a JavaWorld
Node4J: Running Node.js in a JavaWorldNode4J: Running Node.js in a JavaWorld
Node4J: Running Node.js in a JavaWorld
 
Multi-provider Vagrant and Chef: AWS, VMware, and more
Multi-provider Vagrant and Chef: AWS, VMware, and moreMulti-provider Vagrant and Chef: AWS, VMware, and more
Multi-provider Vagrant and Chef: AWS, VMware, and more
 
Deploying PHP Applications with Ansible
Deploying PHP Applications with AnsibleDeploying PHP Applications with Ansible
Deploying PHP Applications with Ansible
 

Ähnlich wie Multiple django applications on a single server with nginx

Django deployment and rpm+yum
Django deployment and rpm+yumDjango deployment and rpm+yum
Django deployment and rpm+yum
Walter Liu
 

Ähnlich wie Multiple django applications on a single server with nginx (20)

Socket programming, and openresty
Socket programming, and openrestySocket programming, and openresty
Socket programming, and openresty
 
NGINX Installation and Tuning
NGINX Installation and TuningNGINX Installation and Tuning
NGINX Installation and Tuning
 
DevFest 2022 - Cloud Workstation Introduction TaiChung
DevFest 2022 - Cloud Workstation Introduction TaiChungDevFest 2022 - Cloud Workstation Introduction TaiChung
DevFest 2022 - Cloud Workstation Introduction TaiChung
 
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
 
BaseX user-group-talk XML Prague 2013
BaseX user-group-talk XML Prague 2013BaseX user-group-talk XML Prague 2013
BaseX user-group-talk XML Prague 2013
 
Docker Enterprise Workshop - Technical
Docker Enterprise Workshop - TechnicalDocker Enterprise Workshop - Technical
Docker Enterprise Workshop - Technical
 
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
ITB2019 NGINX Overview and Technical Aspects - Kevin JonesITB2019 NGINX Overview and Technical Aspects - Kevin Jones
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
 
An introduction to Node.js application development
An introduction to Node.js application developmentAn introduction to Node.js application development
An introduction to Node.js application development
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEA
 
ContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven InfrastructureContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven Infrastructure
 
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScript
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScriptENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScript
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScript
 
Crikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor WorkshopCrikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor Workshop
 
IoT-javascript-2019-fosdem
IoT-javascript-2019-fosdemIoT-javascript-2019-fosdem
IoT-javascript-2019-fosdem
 
NGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best PracticesNGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best Practices
 
App Deployment on Cloud
App Deployment on CloudApp Deployment on Cloud
App Deployment on Cloud
 
OWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA TestersOWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA Testers
 
Akash rajguru project report sem v
Akash rajguru project report sem vAkash rajguru project report sem v
Akash rajguru project report sem v
 
PyConIE 2017 Writing and deploying serverless python applications
PyConIE 2017 Writing and deploying serverless python applicationsPyConIE 2017 Writing and deploying serverless python applications
PyConIE 2017 Writing and deploying serverless python applications
 
Django deployment and rpm+yum
Django deployment and rpm+yumDjango deployment and rpm+yum
Django deployment and rpm+yum
 
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
 

Mehr von roskakori

Mehr von roskakori (18)

Expanding skill sets - Broaden your perspective on design
Expanding skill sets - Broaden your perspective on designExpanding skill sets - Broaden your perspective on design
Expanding skill sets - Broaden your perspective on design
 
Django trifft Flutter
Django trifft FlutterDjango trifft Flutter
Django trifft Flutter
 
Helpful pre commit hooks for Python and Django
Helpful pre commit hooks for Python and DjangoHelpful pre commit hooks for Python and Django
Helpful pre commit hooks for Python and Django
 
Startmeeting Interessengruppe NLP NLU Graz
Startmeeting Interessengruppe NLP NLU GrazStartmeeting Interessengruppe NLP NLU Graz
Startmeeting Interessengruppe NLP NLU Graz
 
Helpful logging with python
Helpful logging with pythonHelpful logging with python
Helpful logging with python
 
Helpful logging with Java
Helpful logging with JavaHelpful logging with Java
Helpful logging with Java
 
Einführung in Kommunikation und Konfliktmanagement für Software-Entwickler
Einführung in Kommunikation und Konfliktmanagement für Software-EntwicklerEinführung in Kommunikation und Konfliktmanagement für Software-Entwickler
Einführung in Kommunikation und Konfliktmanagement für Software-Entwickler
 
Analyzing natural language feedback using python
Analyzing natural language feedback using pythonAnalyzing natural language feedback using python
Analyzing natural language feedback using python
 
Microsoft SQL Server with Linux and Docker
Microsoft SQL Server with Linux and DockerMicrosoft SQL Server with Linux and Docker
Microsoft SQL Server with Linux and Docker
 
Migration to Python 3 in Finance
Migration to Python 3 in FinanceMigration to Python 3 in Finance
Migration to Python 3 in Finance
 
Introduction to pygments
Introduction to pygmentsIntroduction to pygments
Introduction to pygments
 
Lösungsorientierte Fehlerbehandlung
Lösungsorientierte FehlerbehandlungLösungsorientierte Fehlerbehandlung
Lösungsorientierte Fehlerbehandlung
 
XML namespaces and XPath with Python
XML namespaces and XPath with PythonXML namespaces and XPath with Python
XML namespaces and XPath with Python
 
Erste-Hilfekasten für Unicode mit Python
Erste-Hilfekasten für Unicode mit PythonErste-Hilfekasten für Unicode mit Python
Erste-Hilfekasten für Unicode mit Python
 
Introduction to trader bots with Python
Introduction to trader bots with PythonIntroduction to trader bots with Python
Introduction to trader bots with Python
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with python
 
Python builds mit ant
Python builds mit antPython builds mit ant
Python builds mit ant
 
Kanban zur Abwicklung von Reporting-Anforderungen
Kanban zur Abwicklung von Reporting-AnforderungenKanban zur Abwicklung von Reporting-Anforderungen
Kanban zur Abwicklung von Reporting-Anforderungen
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 

Multiple django applications on a single server with nginx

  • 1. Multiple Django applications on a single server with nginx PyGRAZ November 2021 Thomas Aglassinger v1.1
  • 2. Goals ● A Django application runs on a Ubuntu 20 LTS. ● The application automatically starts on reboot. ● The application can be controlled with systemctl. ● Web content is served using the lightweight nginx server (no Apache2 bloat). ● The application uses HTTPS with its own (free) certificate. ● Multiple applications can run on the same physical server.
  • 3. Advantages Pros ● Works with Ubuntu 20 LTS standard packages ● Minimal intrusion ● Minimal resource overhead ● Transparent and relatively easy to understand Cons ● You need to build something for deployment yourself (script with ssh/scp, git pull, ...) ● Doesn’t make you feel as powerful as container orchestration approaches.
  • 4. Example We want a Django application that: ● Has the application code stored in /var/www/<environment>/example/ with <environment> being test, stage, production, ... ● Can be accessed using the domain www.example.com ● Uses HTTPS with its own free certificate ● Redirects HTTP to HTTPS
  • 5. Install required packages ● Upgrade to current packages: sudo apt-get -y upgrade ● Install nginx, python3 and certbot: sudo apt-get -y install certbot python3-certbot-nginx (Note: The dependencies ensure that nginx and python3 are installed with this automatically.)
  • 6. Setup additional directories ● Assumption: For now, we want to setup the example application in the test environment. → The application will reside in /var/www/test/example/ ● For a simple installation, you can choose to serve static and media files via nginx → Create the required directories: sudo mkdir -p "/var/www/test/example/media" sudo mkdir -p "/var/www/test/example/static"
  • 7. Install your Django application ● Copy your code to /var/www/test/example/ ● Set up a virtual environment using whatever venv tool is in fashion, for example: sudo apt-get -y install python3-venv cd /var/www/test/example/ sudo python3 -m venv venv . venv/bin/activate ● Install dependent python packages, including gunicorn
  • 8. Service architecture nginx gunicorn Django application Socket WSGI ● WSGI: “Web Server Gateway Interface”, to forward requests to web services written in Python ● gunicorn: Python WSGI HTTP Server for UNIX; “simply implemented, light on server resources, and fairly speedy”
  • 9. /etc/systemd/system/example.socket [Unit] Description=gunicorn socket for example [Socket] ListenStream=/run/example.sock [Install] WantedBy=sockets.target
  • 10. /etc/systemd/system/example.service [Unit] Description=gunicorn daemon for example Requires=example.socket After=network.target [Service] User=www-data Group=www-data WorkingDirectory=/var/www/test/example ExecStart=/var/www/test/example/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/example.sock example.wsgi:application [Install] WantedBy=multi-user.target
  • 11. /etc/systemd/system/example.service [Unit] Description=gunicorn daemon for example Requires=example.socket After=network.target [Service] User=www-data Group=www-data WorkingDirectory=/var/www/test/example ExecStart=/var/www/test/example/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/example.sock example.wsgi:application [Install] WantedBy=multi-user.target Change to as many processes as needed. Standard user for web service Wait for socket service from before. gunicorn in venv from before
  • 12. /etc/nginx/sites-available/www.example.com server { listen 80; server_name www.example.com; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { root /var/www/test/example; } location / { include proxy_params; proxy_pass http://unix:/run/example.sock; } }
  • 13. /etc/nginx/sites-available/www.example.com server { listen 80; server_name www.example.com; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { root /var/www/test/example; } location / { include proxy_params; proxy_pass http://unix:/run/example.sock; } } socket service from before. Our domain For now, use plain HTTP Serve static files
  • 14. Activate nginx configuration ● Activation is done by linking the enabled configuration to the available one: sudo ln -s /etc/nginx/sites-available/www.example.com /etc/nginx/sites-enabled ● Because this is a link and not a copy, changes in the available configuration also reflect on the enabled one. ● After changes restart nginx: sudo systemctl restart nginx
  • 15. Common tasks ● Restart the service (e.g. after deployment) sudo systemctl daemon-reload sudo systemctl restart example ● Analyze possible errors when starting the application: sudo journalctl -u example ● Analyze log files: sudo tail -f /var/log/nginx/error.log sudo tail -f /var/log/nginx/access.log
  • 16. Easy mode for most files ● nubops from https://github.com/roskakori/nubops (from gamer slang: nub → noob → newbie) ● Generate most of the files by running: sudo nubops nginx-django test example www.example.com ● Available on PyPI soon.
  • 17. Enable HTTPS ● sudo certbot --agree-tos -d www.example.com -n --nginx
  • 18. Done! ● Fairly lightweight infrastructure. ● Few and small configurations file. ● Well integrated into systemd. ● Secure connections. ● Transparent error tracking.