- Clone the code from git (github/bitbucket/gitlab)
- Install the dependency
- run the celery worker (if needed)
- run the celery beat (if needed)
- run any other service (if needed)
-
install uwsgi (for example: pip install uwsgi)
-
Create a .ini file in
/etc/uwsgi/
with nameyour_domain_name.ini
(for example: nano /etc/uwsgi/your_domain_name.ini) -
Add the following code in the file
[uwsgi] project = your_project_name # Example: project = invogo base = /home/your_user_name # Example: base = /home/ajitmourya chdir = %(base)/%(project) # Example: chdir = /home/ajitmourya/invogo home = %(base)/.pyenv/versions/your_python_version # Example: home = /home/ajitmourya/.pyenv/versions/3.8.6/envs/invogo module = %(project).wsgi:application # Example: module = invogo.wsgi:application master = true processes = 5 # Example: no of processes (its depend on number of cpu) = 5 socket = /tmp/%(project).sock # Example: socket = /tmp/invogo.sock chmod-socket = 666 vacuum = true
-
Create a service file in
/etc/systemd/system/
with nameyour_domain_name.service
(for example: nano /etc/systemd/system/your_domain_name.service) -
Add the following code in the file
[Unit] Description=uWSGI instance to serve your_project_name After=network.target [Service] User=your_user_name # Example: User=ajitmourya Group=www-data WorkingDirectory=/home/your_user_name/your_project_name # Example: WorkingDirectory=/home/ajitmourya/invogo Environment="PATH=/home/your_user_name/.pyenv/versions/your_python_version/bin" # Example: Environment="PATH=/home/ajitmourya/.pyenv/versions/3.8.6/bin" ExecStart=/home/your_user_name/.pyenv/versions/your_python_version/bin/uwsgi --ini /etc/your_domain_name.ini # Example: ExecStart=/home/ajitmourya/.pyenv/versions/3.8.6/bin/uwsgi --ini /etc/uwsgi/invogo.ini [Install] WantedBy=multi-user.target
-
Enable the service (for example: sudo systemctl enable your_domain_name)
-
Start the service (for example: sudo systemctl start your_domain_name)
-
Check the status of the service (for example: sudo systemctl status your_domain_name)
-
Restart the service (for example: sudo systemctl restart your_domain_name)
-
Stop the service (for example: sudo systemctl stop your_domain_name)
- Install nginx
- Configure nginx
- Create a file in
/etc/nginx/sites-available/
with nameyour_domain_name
(for example: nano /etc/nginx/sites-available/your_domain_name) - Add the following code in the file
server { listen 80; server_name your_domain_name; location / { include uwsgi_params; uwsgi_pass unix:/tmp/your_project_name.sock; # Example: uwsgi_pass unix:/tmp/invogo.sock; } }
- Create a symbolic link in
/etc/nginx/sites-enabled/
(for example: ln -s /etc/nginx/sites-available/your_domain_name /etc/nginx/sites-enabled)
- Create a file in
- Check the nginx configuration (for example: sudo nginx -t)
- Restart the nginx (for example: sudo systemctl restart nginx)
map the domain name with your server ip address with A record in DNS server