SlideShare a Scribd company logo
Gunicorn with Nginx Setup
• 1. What is Gunicorn?
• 2. What is Nginx?
3. Why Gunicorn and Nginx?
• 4. Steps to create User and Group
5. Deploy.sh
• 6. Gunicorn Setup
• 7. Nginx Setup
• 8. What is SSL certificate?
• 9. How do SSL certificates work?
• 10. Why you need an SSL certificate?
• 11. Configure Certbot for SSL Certificate
• 12. Benefits with Ngix and Gunicorn
What is Gunicorn?
• Gunicorn implements the Web Server Gateway Interface (WSGI), which is a
standard interface between web server software and web applications.
• 1. Gunicorn (Green Unicorn) is a WSGI HTTP server for Python Web
applications.
• 2. Designed to be lightweight, simple and fast.
• 3. WSGI (Web Server Gateway Interface) is a standard interface between web
servers and Python web applications.
What is Nginx?
• Nginx is a web server. It's the public handler, more formally called
the reverse proxy, for incoming requests and scales to thousands of
simultaneous connections.
• 1. Nginx is a high performance, open source web server and
reverse proxy server.
• 2. Know for its scalability and low resources consumption.
• 3. Commonly used to server static content, revers proxy and
• load balancing.
Nginx
Why Gunicorn and Nginx?
• 1. Gunicorn handles dynamic content and interect with the
python web applications.
• 2. Nginx handles static content, SSL terminations and acts as a
reverse proxy.
• 3. Combined, they provide a scalable and efficient web server
setup.
Steps to create User and Group
1. Create a new user "“Servicename”" + create a new Group for the new user. (sudo useradd -m “Servicename
2. Add Ubuntu and www-data to “Servicename”'s new group. (sudo adduser ubuntu “Servicename”)
 (sudo adduser ubuntu www-data)
3. Give permission to /home/”Servicename”/ (sudo chmod -R g+w /home/”Servicename”/)
4. Configure Ngix file
5. Create a symbolic link (sudo ln -s/bin/python/usr/local/bin/python3.10)
6. Create a virtual environment (python -m venv vm)
7. Install requried packages (pip install -r requirements.txt)
PostgreSQL
• 1. Set a password if not configured.
• 2. Create login group Roles
• 3. Create a Database with owner “Servicename” rights
Deploy.sh
• git push
cd ..
rm -f project-deploy.tar.gz
rm -rf project-deploy
git clone <git repository name> project-deploy --depth 1
tar --exclude-vcs -cvzf project-deploy.tar.gz project-deploy
scp -C project-deploy.tar.gz ubuntu@abc.com:~/
ssh ubuntu@abc.com <<-SCRIPT
tar -xvzf project-deploy.tar.gz
rm -rf project
mv project-deploy project
cd project
ln -s ../kyc kyc;
source ../project_env/bin/activate
python manage.py migrate;
python manage.py collectstatic --no-input;
sudo service project restart;
sudo service nginx restart;
SCRIPT
Gunicorn Setup
• 1. Installation: pip install gunicorn
• 1.1 Open your Linux terminal or shell.
• 1.2 Type “ pip install gunicorn ” (without quotes), hit Enter.
• 1.3 If it doesn't work, try "pip3 install gunicorn" or “ python -m pip install gunicorn “.
• 1.4 Wait for the installation to terminate successfully.
• 2. After installing Gunicorn you will have access to the command line script gunicorn.
Running Gunicorn command:
• -> gunicorn myapp:app
• 3. Configuration options (workers, bind address, etc.)
• 4. Example command: gunicorn -w 4 -b 0.0.0.0:8000 myapp:app
Gunicorn Setup
• 1. gunicorn: This is the command to start the Gunicorn server.
• 2. -w 4: This option specifies the number of worker processes Gunicorn should use. In
this case, it is set to 4. Worker processes are separate instances of the application that
handle incoming requests concurrently. Adjusting the number of workers can impact the
server's performance.
• 3. -b 0.0.0.0:8000: This option specifies the socket to bind Gunicorn to. In this case, it
binds to all available network interfaces (0.0.0.0) on port 8000. This means the server will
listen for incoming connections on port 8000 and be accessible from any IP address.
• 4. myapp:app: This argument specifies the location of the WSGI application object. In
this example, it assumes your application is in a file named myapp (without the file
extension) and the WSGI application object is named app. This could vary based on the
structure of your project.
Nginx Setup
• 1. Installation: sudo apt-get install nginx
1.1 Installing Nginx. To install Nginx, use following command: sudo apt update sudo apt install nginx. ...
• 1.2 Creating our own website. Default page is placed in /var/www/html/ location. ...
• 1.3 Setting up virtual host. ...
• 1.4 Activating virtual host and testing results.
• 2. Basic configuration: server blocks, location blocks
 server {
 listen 80;
 server_name abc.com;
 . . .
 }
• 3. Reverse proxy configuration for Gunicorn
• 3.1 A reverse proxy is a server that sits between client devices (such as web browsers) and a backend server.
• 3.2 It performs tasks on behalf of the server, acting as an intermediary between clients and the actual server hosting the
application.
• 3.3 Unlike a forward proxy, which handles requests from clients to the internet, a reverse proxy handles requests from clients to
a server.
• 4. Example Nginx configuration snippet:
What is SSL certificate
• 1. An SSL certificate is a digital certificate that authenticates
website’s identity and enables an encrypted connection.
• 2. SSL stands for Secure Socket Layer, a security protocol that
creates an encrypted link between a web server and a web
browser.
How do SSL certificates work?
• 1. A browser or server attempts to connect a website(i. g. Web server)
secured with SSL.
• 2. The browser or server requests that the web server identifies itself.
• 3. The web server sends the browser or server a copy of its SSL certificate in
response.
• 4. The browser or server checks to see whether it trusts the SSL certificate. If
it does, it signals this to the webserver.
• 5. The web server then returns a digitally signed acknowledgment to start an
SSL encrypted session.
• 6. Encrypted data is shared between the browser or server and the
webserver.
Why you need an SSL certificate
• 1. Login Credentials.
• 2. Credit card transactions and bank account informations.
• 3. Personally identifiable information – such as full name ,
address, date of birth or mobile number.
• 4. Legal documents and contracts.
• 5. Medical records.
• 6. Proprietary information.
Configure Certbot for SSL
Certificate
• 1. Update package Lists (sudo apt-get update)
• 2. Install certbot (sudo apt-get install certbot)
• 3. Install certbot nginx plugin (sudo apt-get install python3-
certbot-nginx)
• 4. Obtain SSL / TLS Certificates (sudo certbot)
Benefits of Gunicorn and Nginx
• 1. Gunicorn provides a simple and efficient WSGI server for Python
• 2. Nginx handles static files, improves security, and enhances
performance
• 3. Improved scalability and resource utilization
Demo
Demo link:- https://youtu.be/tnJBalPzeAo?si=4XNQwmn-EVahGS9y
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-
with-postgres-nginx-and-gunicorn-on-ubuntu

More Related Content

Similar to Nginx-deploy on linux server with 80 and 442 (20)

PPTX
NGINX 101 - now with more Docker
sarahnovotny
 
PPTX
NGINX 101 - now with more Docker
Sarah Novotny
 
PDF
Install nginx on ubuntu 21.04 server
LinuxConcept
 
PDF
NGiNX, VHOSTS & SSL (let's encrypt)
Marcel Cattaneo
 
PPTX
NGINX Basics: Ask Me Anything – EMEA
NGINX, Inc.
 
PDF
DockerCon Live 2020 - Securing Your Containerized Application with NGINX
Kevin Jones
 
PPTX
NGINX: Basics and Best Practices
NGINX, Inc.
 
PPTX
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
Amit Aggarwal
 
PPTX
NGINX Installation and Tuning
NGINX, Inc.
 
PDF
Nginx
Shaopeng He
 
PPTX
How To Create a SSL Certificate on Nginx for Ubuntu.pptx
VEXXHOST Private Cloud
 
ODP
Introduction to Nginx
Knoldus Inc.
 
PDF
Complete-NGINX-Cookbook-2019.pdf
TomaszWojciechowski22
 
PDF
How to Set Up Nginx Server Blocks on Ubuntu 2404.pdf
Green Webpage
 
PPTX
NGINX: Back to Basics – APCJ
NGINX, Inc.
 
PPTX
NGINX: High Performance Load Balancing
NGINX, Inc.
 
PDF
Nginx cheat sheet
Lam Hoang
 
PPTX
Nginx Deep Dive Kubernetes Ingress
Knoldus Inc.
 
PDF
What’s New in NGINX Plus R15? - EMEA
NGINX, Inc.
 
PDF
Deliver Python Apps with Docker
Anton Egorov
 
NGINX 101 - now with more Docker
sarahnovotny
 
NGINX 101 - now with more Docker
Sarah Novotny
 
Install nginx on ubuntu 21.04 server
LinuxConcept
 
NGiNX, VHOSTS & SSL (let's encrypt)
Marcel Cattaneo
 
NGINX Basics: Ask Me Anything – EMEA
NGINX, Inc.
 
DockerCon Live 2020 - Securing Your Containerized Application with NGINX
Kevin Jones
 
NGINX: Basics and Best Practices
NGINX, Inc.
 
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
Amit Aggarwal
 
NGINX Installation and Tuning
NGINX, Inc.
 
How To Create a SSL Certificate on Nginx for Ubuntu.pptx
VEXXHOST Private Cloud
 
Introduction to Nginx
Knoldus Inc.
 
Complete-NGINX-Cookbook-2019.pdf
TomaszWojciechowski22
 
How to Set Up Nginx Server Blocks on Ubuntu 2404.pdf
Green Webpage
 
NGINX: Back to Basics – APCJ
NGINX, Inc.
 
NGINX: High Performance Load Balancing
NGINX, Inc.
 
Nginx cheat sheet
Lam Hoang
 
Nginx Deep Dive Kubernetes Ingress
Knoldus Inc.
 
What’s New in NGINX Plus R15? - EMEA
NGINX, Inc.
 
Deliver Python Apps with Docker
Anton Egorov
 

Recently uploaded (20)

PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Ad

Nginx-deploy on linux server with 80 and 442

  • 1. Gunicorn with Nginx Setup • 1. What is Gunicorn? • 2. What is Nginx? 3. Why Gunicorn and Nginx? • 4. Steps to create User and Group 5. Deploy.sh • 6. Gunicorn Setup • 7. Nginx Setup • 8. What is SSL certificate? • 9. How do SSL certificates work? • 10. Why you need an SSL certificate? • 11. Configure Certbot for SSL Certificate • 12. Benefits with Ngix and Gunicorn
  • 2. What is Gunicorn? • Gunicorn implements the Web Server Gateway Interface (WSGI), which is a standard interface between web server software and web applications. • 1. Gunicorn (Green Unicorn) is a WSGI HTTP server for Python Web applications. • 2. Designed to be lightweight, simple and fast. • 3. WSGI (Web Server Gateway Interface) is a standard interface between web servers and Python web applications.
  • 3. What is Nginx? • Nginx is a web server. It's the public handler, more formally called the reverse proxy, for incoming requests and scales to thousands of simultaneous connections. • 1. Nginx is a high performance, open source web server and reverse proxy server. • 2. Know for its scalability and low resources consumption. • 3. Commonly used to server static content, revers proxy and • load balancing.
  • 5. Why Gunicorn and Nginx? • 1. Gunicorn handles dynamic content and interect with the python web applications. • 2. Nginx handles static content, SSL terminations and acts as a reverse proxy. • 3. Combined, they provide a scalable and efficient web server setup.
  • 6. Steps to create User and Group 1. Create a new user "“Servicename”" + create a new Group for the new user. (sudo useradd -m “Servicename 2. Add Ubuntu and www-data to “Servicename”'s new group. (sudo adduser ubuntu “Servicename”)  (sudo adduser ubuntu www-data) 3. Give permission to /home/”Servicename”/ (sudo chmod -R g+w /home/”Servicename”/) 4. Configure Ngix file 5. Create a symbolic link (sudo ln -s/bin/python/usr/local/bin/python3.10) 6. Create a virtual environment (python -m venv vm) 7. Install requried packages (pip install -r requirements.txt) PostgreSQL • 1. Set a password if not configured. • 2. Create login group Roles • 3. Create a Database with owner “Servicename” rights
  • 7. Deploy.sh • git push cd .. rm -f project-deploy.tar.gz rm -rf project-deploy git clone <git repository name> project-deploy --depth 1 tar --exclude-vcs -cvzf project-deploy.tar.gz project-deploy scp -C project-deploy.tar.gz [email protected]:~/ ssh [email protected] <<-SCRIPT tar -xvzf project-deploy.tar.gz rm -rf project mv project-deploy project cd project ln -s ../kyc kyc; source ../project_env/bin/activate python manage.py migrate; python manage.py collectstatic --no-input; sudo service project restart; sudo service nginx restart; SCRIPT
  • 8. Gunicorn Setup • 1. Installation: pip install gunicorn • 1.1 Open your Linux terminal or shell. • 1.2 Type “ pip install gunicorn ” (without quotes), hit Enter. • 1.3 If it doesn't work, try "pip3 install gunicorn" or “ python -m pip install gunicorn “. • 1.4 Wait for the installation to terminate successfully. • 2. After installing Gunicorn you will have access to the command line script gunicorn. Running Gunicorn command: • -> gunicorn myapp:app • 3. Configuration options (workers, bind address, etc.) • 4. Example command: gunicorn -w 4 -b 0.0.0.0:8000 myapp:app
  • 9. Gunicorn Setup • 1. gunicorn: This is the command to start the Gunicorn server. • 2. -w 4: This option specifies the number of worker processes Gunicorn should use. In this case, it is set to 4. Worker processes are separate instances of the application that handle incoming requests concurrently. Adjusting the number of workers can impact the server's performance. • 3. -b 0.0.0.0:8000: This option specifies the socket to bind Gunicorn to. In this case, it binds to all available network interfaces (0.0.0.0) on port 8000. This means the server will listen for incoming connections on port 8000 and be accessible from any IP address. • 4. myapp:app: This argument specifies the location of the WSGI application object. In this example, it assumes your application is in a file named myapp (without the file extension) and the WSGI application object is named app. This could vary based on the structure of your project.
  • 10. Nginx Setup • 1. Installation: sudo apt-get install nginx 1.1 Installing Nginx. To install Nginx, use following command: sudo apt update sudo apt install nginx. ... • 1.2 Creating our own website. Default page is placed in /var/www/html/ location. ... • 1.3 Setting up virtual host. ... • 1.4 Activating virtual host and testing results. • 2. Basic configuration: server blocks, location blocks  server {  listen 80;  server_name abc.com;  . . .  } • 3. Reverse proxy configuration for Gunicorn • 3.1 A reverse proxy is a server that sits between client devices (such as web browsers) and a backend server. • 3.2 It performs tasks on behalf of the server, acting as an intermediary between clients and the actual server hosting the application. • 3.3 Unlike a forward proxy, which handles requests from clients to the internet, a reverse proxy handles requests from clients to a server. • 4. Example Nginx configuration snippet:
  • 11. What is SSL certificate • 1. An SSL certificate is a digital certificate that authenticates website’s identity and enables an encrypted connection. • 2. SSL stands for Secure Socket Layer, a security protocol that creates an encrypted link between a web server and a web browser.
  • 12. How do SSL certificates work? • 1. A browser or server attempts to connect a website(i. g. Web server) secured with SSL. • 2. The browser or server requests that the web server identifies itself. • 3. The web server sends the browser or server a copy of its SSL certificate in response. • 4. The browser or server checks to see whether it trusts the SSL certificate. If it does, it signals this to the webserver. • 5. The web server then returns a digitally signed acknowledgment to start an SSL encrypted session. • 6. Encrypted data is shared between the browser or server and the webserver.
  • 13. Why you need an SSL certificate • 1. Login Credentials. • 2. Credit card transactions and bank account informations. • 3. Personally identifiable information – such as full name , address, date of birth or mobile number. • 4. Legal documents and contracts. • 5. Medical records. • 6. Proprietary information.
  • 14. Configure Certbot for SSL Certificate • 1. Update package Lists (sudo apt-get update) • 2. Install certbot (sudo apt-get install certbot) • 3. Install certbot nginx plugin (sudo apt-get install python3- certbot-nginx) • 4. Obtain SSL / TLS Certificates (sudo certbot)
  • 15. Benefits of Gunicorn and Nginx • 1. Gunicorn provides a simple and efficient WSGI server for Python • 2. Nginx handles static files, improves security, and enhances performance • 3. Improved scalability and resource utilization