Deploy Django project with Nginx, and Gunicorn on Ubuntu 22.04 |

Поделиться
HTML-код
  • Опубликовано: 12 сен 2024
  • Howdy Programers,
    -------------------------------------------------------------
    Creating systemd Socket and Service Files for Gunicorn
    sudo nano /etc/systemd/system/gunicorn.socket
    paste below code:
    [Unit]
    Description=gunicorn socket
    [Socket]
    ListenStream=/run/gunicorn.sock
    [Install]
    WantedBy=sockets.target
    -------------------------------------------------------------
    sudo nano /etc/systemd/system/gunicorn.service
    paste below code::
    [Unit]
    Description=gunicorn daemon
    Requires=gunicorn.socket
    After=network.target
    [Service]
    User=sammy
    Group=www-data
    WorkingDirectory=/home/sammy/myprojectdir
    ExecStart=/home/sammy/myprojectdir/myprojectenv/bin/gunicorn \
    --access-logfile - \
    --workers 3 \
    --bind unix:/run/gunicorn.sock \
    myproject.wsgi:application
    [Install]
    WantedBy=multi-user.target
    -------------------------------------------------------------
    sudo systemctl start gunicorn.socket
    sudo systemctl enable gunicorn.socket
    sudo systemctl status gunicorn.socket
    -------------------------------------------------------------
    Configure Nginx to Proxy Pass to Gunicorn
    sudo nano /etc/nginx/sites-available/myproject
    paste below code:
    server {
    listen 80;
    server_name server_domain_or_IP;
    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
    root /home/sammy/myprojectdir;
    }
    location / {
    include proxy_params;
    proxy_pass unix:/run/gunicorn.sock;
    }
    }
    sudo ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled
    -------------------------------------------------------------
    Thank you
    Regards
    Official Tech
    --------------------------------------------------------------
    Code: github.com/off...
    Video: / officialtechjb
    Home: hindbay.com
    Services: fourthX.com

Комментарии • 28

  • @d1n086
    @d1n086 5 месяцев назад +1

    I spent almost 7 hours on this, and i finally did it in 30 minutes with your video. Thanks you very very very much!

  • @_friendly_angel9527
    @_friendly_angel9527 6 месяцев назад

    After searching and watching millions of videos with Hindus you solved my problem which was not solved for the 3rd day. Respect!

  • @ushared-a-chregion3720
    @ushared-a-chregion3720 Месяц назад

    Really good explanation, works very well! ;)

    • @otJB
      @otJB  Месяц назад

      Thank you... 🤩🤩🤩

  • @phpkishorekishore
    @phpkishorekishore 3 месяца назад

    Thank you, it saved my hours of time.

    • @otJB
      @otJB  3 месяца назад

      Thank you a lot!

  • @DmitryLaierCrypto
    @DmitryLaierCrypto 3 месяца назад

    Thx for tutorial. One question, are you copying from the clipboard default nginx configuration text? Or some assistant do this? Because the most important part that connects the gunicorn socket with nginx is not explained. THX!

    • @officialtech3010
      @officialtech3010 3 дня назад

      You can copy paste default configuration for gunicorn from internet

  • @SUJALSAHU-vg2sj
    @SUJALSAHU-vg2sj 2 месяца назад

    thanks the video is very helpful

    • @otJB
      @otJB  Месяц назад

      Thank you Sujal... 🤩🤩🤩

  • @tornjak096
    @tornjak096 3 месяца назад

    So what are the steps if I have my finished project on local disk. Should I copy and paste all files to server, what about requirments.txt and so on ...

    • @otJB
      @otJB  3 месяца назад

      you need to put all the files there on server as well as requirements.txt and you have create the environment and install all the dependencies and so on...

  • @multimilmobr7795
    @multimilmobr7795 4 месяца назад

    Thank you, it helped a lot, do you have another video showing it and putting it on https?

    • @otJB
      @otJB  3 месяца назад

      No, not yet...

  • @vb52ru
    @vb52ru 2 месяца назад

    Thank you

  • @chrisowuor605
    @chrisowuor605 4 месяца назад

    hello great content but how can I configure the nginx to serve two Django apps in my ec2 instance on different ports using the public IP of the instance as server name

    • @otJB
      @otJB  4 месяца назад

      sudo apt update
      sudo apt install nginx
      sudo nano /etc/nginx/sites-available/app1
      paste this code
      server {
      listen 80;
      server_name YOUR_PUBLIC_IP;
      location / {
      proxy_pass localhost:8000;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      }
      }
      sudo nano /etc/nginx/sites-available/app2
      paste this
      server {
      listen 80;
      server_name YOUR_PUBLIC_IP;
      location / {
      proxy_pass localhost:9000;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      }
      }
      Enable Server Blocks
      sudo ln -s /etc/nginx/sites-available/app1 /etc/nginx/sites-enabled/
      sudo ln -s /etc/nginx/sites-available/app2 /etc/nginx/sites-enabled/
      sudo systemctl restart nginx

    • @chrisowuor605
      @chrisowuor605 4 месяца назад

      @@otJB Thanks for the reply though it says the server name for app1 will be ignored since it's the same public IP of my ec2 instance I was thinking of a way in which I can use the same public IP of my e2 instance to serve both apps running in different ports based on the location params in the nginx configuration like /home to serve app1 and /app1 to server app2

  • @sebastiansebastiana5499
    @sebastiansebastiana5499 8 месяцев назад

    But if you created an apiview, could I consume it? implemented this way of deploying

    • @otJB
      @otJB  8 месяцев назад

      Yes

  • @alexdin1565
    @alexdin1565 5 месяцев назад

    please can you make a video on how we can deployit with docker?

    • @otJB
      @otJB  4 месяца назад

      Hey there! Thanks for reaching out. Right now, I'm a bit tied up with some other projects, but I hope to dive into creating that video in the future. Deploying with Docker sounds like a great topic to cover, so stay tuned, and hopefully, I'll have something for you soon! Thank you!

  • @chimaezeorah4713
    @chimaezeorah4713 6 месяцев назад

    great video! my static files are not still loaded not sure why

    • @chimaezeorah4713
      @chimaezeorah4713 6 месяцев назад

      nevermind i linked the wrong conf file. works thank you

  • @fraziersingo5056
    @fraziersingo5056 10 месяцев назад

    🤪 Promo-SM

  • @ahmadumar9387
    @ahmadumar9387 5 месяцев назад

    should i develop every django project in /var/www/html/... my django project?

    • @otJB
      @otJB  4 месяца назад +1

      you can deploy anywhere on the server but need to specify the path on nginx/apache configuration