I have a linux server that run multiple different website on multiple different domain which are working fine.
But I created a sub domain for one of the domain which is demo.mywebsitedomain.com I did the configuration like it was a different domain which mean I created a specific nginx socket / service / nginx config file for this subdomain
But when I go the my link demo.mywebsitedomain.com it run the website application of an other django application folder, it not the one who I have pointed in the socket and service file. I am verry confuse.
It should run the django application whos in the testdemo folder but instead it run a different folder application. Those are the file I created for the subdomain
sudo vim /etc/systemd/system/testdemo.socket
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/testdemo.sock
Environment="PATH=/usr/bin:/home/tiber/testdemo/env/bin"
[Install]
WantedBy=sockets.target
sudo vim /etc/systemd/system/testdemo.service
[Unit]
Description=gunicorn daemon
Requires=testdemo.socket
After=network.target
[Service]
User=tiber
Group=www-data
WorkingDirectory=/home/tiber/testdemo
ExecStart=/home/tiber/testdemo/env/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/testdemo.sock \
mysite.wsgi:application
[Install]
WantedBy=multi-user.target
sudo vim /etc/nginx/sites-available/testdemo
server {
listen 80;
server_name demo.mywebsitedomain.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /var/www/testdemo;
}
location /media/ {
root /var/www/testdemo;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/testdemo.sock;
}
}
Related
I am trying to deploy a simple hello-world Django site to EC2 (Ubuntu 22.04) using Gunicorn and Nginx. Nginx and Gunicorn services are both reporting as running successfully, and the .sock file has been created seemingly without issue.
Gunicorn configuration file:
[Unit]
Description=gunicorn daemon
After=nextwork.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/sites/mysite-main
ExecStart=/home/ubuntu/.local/share/virtualenvs/mysite-main-_EzVOJAm/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ubuntu/sites/mysite-main/mysite-main.sock myapp.wsgi:application
[Install]
WantedBy=multi-user.target
Nginx configuration:
server {
listen 80;
server_name <domainname>.com <ipaddress>;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntu/sites/mysite-main;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/sites/mysite-main/mysite-main.sock;
}
}
Permissions on the .sock file, as well as both the "sites" and "mysite-main" directories are ubuntu:www-data. I attempted to try moving it out of the ubuntu user's home directory into a more "common" location in case it was permissions on the home directory stopping it, but was unable to even get the .sock file to generate in that case, probably due to my unfamliarity with how this works.
It looks like this is one of the most queried problems of all time, but I've tried every solution I could find to no avail. Any help would be greatly appreciated. Thanks in advance!
Very odd behavior from my Ubuntu 18.04 LTS server
I have followed this tutorial here (twice) and it is all working properly except a couple odd things
firstly, when I use my browser to visit the IP of my VPS, the django default application page shows up throughout the tutorial however accessing it through the domain name results in a time out error
secondly, now that I have completed the tutorial and configured nginx to proxy pass to gunicorn, the apache2 ubuntu default page is now displaying instead of the django default page on a visit to the ip address and still no response from the domain name, even though there is no installation of apache2 on this server...
$ whereis apache2
apache2:
here is my gunicorn.socket file
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
here is my gunicorn.service file
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=trends
Group=www-data
WorkingDirectory=/trends_dir
ExecStart=/trends_dir/trendsvenv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
trends.wsgi:application
[Install]
WantedBy=multi-user.target
here is my /etc/nginx/sites-available config file for the site, which has been properly symlinked to /etc/nginx/sites-enabled
server {
listen 80;
server_name www.trendsontheblock.com trendsontheblock.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /trends_dir;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
like i said, no errors from the ip address and cannot get a response from the domain name, any help would be greatly appreciated, thank you
As pointed out by Mohamed in the comments section the error was due to incorrect ip-domain mapping caused by an inconsistent A record value in my domain name hosting service (godaddy)
This was because I had switched from shared hosting to VPS and the domain name's name-server values had therefore become inconsistent
The domain-name server needed to be reset to the default host values and it's A record was updated to the new VPS server's IP this has solved my issue
I'm using the Angular app as a frontend and Django rest framework for backend service and Gunicorn application server to interface with my application and Nginx to reverse proxy to Gunicorn to its security and performance features to serve my app.
There is one request for uploading the file to the server and it fails when the file is large (about 100mb) and the internet is slow and everything is fine with small files (under 10mb).
Here are errors that I get
net::ERR_TIMED_OUT
net::ERR_HTTP2_PING_FAILED
net::ERR_CONNECTION_RESET
Here is my Nginx config:
location ~ ^(/upload_video/[^/]+) {
keepalive_timeout 128;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
client_max_body_size 100M;
proxy_pass http://unix:/run/gunicorn.sock;
}
And here is my Gunicorn service:
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/rest_api
ExecStart=/home/ubuntu/hediehchi_rest_api/myenv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--timeout 180 \
--bind unix:/run/gunicorn.sock \
webapp.wsgi:application
[Install]
WantedBy=multi-user.target
What's the problem? comment below if any information needs to be added.
If you want to upload 100MB, you need a client_max_body_size this is somewhat larger. Second the timeout you're looking for is client_body_timeout.
I have DjangoServer1 and DjangoServer2 running a virtualenv, where gunicorn is installed. nginx is installed under user in Ubuntu.
I make DjangoServer1 running under nginx, gunicorn.
Server IP: 12.12.12.12
Web site domain for DjangoServer1 is mydomain1.com
Web site domain for DjangoServer2 is mydomain2.com
This is nginx server config for DjangoServer1.
/etc/nginx/sites-available/DjangoServer1
server {
listen 0.0.0.0:80;
server_name 127.0.0.1;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/user/develop/DjangoServer1;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/user/develop/DjangoServer1/DjangoServer1.sock;
}
}
I start the DjangoServer1:
1) Under virtualenv, run gunicorn command to start DjangoServer1
gunicorn --daemon --workers 3 --bind unix:/home/user/develop/DjangoServer1/DjangoServer1.sock DjangoServer1.wsgi
2) Then, run:
sudo service nginx restart
3) In router, I portforward port 80, 8000, to server 12.12.12.12
4) In browser, enter: 12.12.12.12. DjangoServer1 works. Enter: mydomain1.com, DjangoServer1 works.
Now, I want to run DjangoServer2 under same server: 12.12.12.12
Question: How to configure DjangoServer1 and DjangoServer2 to different port?
How to run gunicorn command to use different port? Following command uses port 8000? Why?
gunicorn --daemon --workers 3 --bind unix:/home/user/develop/DjangoServer1/DjangoServer1.sock DjangoServer1.wsgi
How to configure nginx file?
Change your Gunicorn command to run the servers on the specified port.
gunicorn --daemon --workers 3 --bind :8080 DjangoServer1.wsgi
Now change your NGINX conf file to forward it to the Application Server.
upstream django-server-1 {
server 0.0.0.0:8080;
}
server {
listen 0.0.0.0:80;
server_name 127.0.0.1;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/user/develop/DjangoServer1;
}
location / {
include proxy_params;
proxy_pass http://django-server-1;
proxy_next_upstream off;
}
}
Restart your NGINX service.
This will forward all the requests coming to 80 port to your application server DjangoServer1.
If you explicitly want to forward requests coming to 8080 to your application server, change the server block in the NGINX configuration or have a new server block with your rules.
Okay so I have been working on this for awhile now and I know many people have had similar problems to myself but I can't seem to find the right solution.
Anyway I have followed the tutorial exactly as laid out on Digital Ocean
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04
everything works fine when I test gunicorn with
gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application
however when I create a systemd file and try to create a proxy pass with nginx I receive a 502 bad gateway error.
when I run:
sudo tail -f /var/log/nginx/error.log
I get error message:
15:18:39 [crit] 10558#10558: *1 connect() to unix:/home/bmhinformatics/Desktop/ProvCaRe/ProvCaRe.sock failed (2: No such file or directory) while connecting to upstream
my gunicorn systemd file looks like:
/etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/usr/myproject
ExecStart=/home/usr/myproject/myprojectenv/bin/gunicorn --workers 3 --bind unix:/home/usr/myproject/myproject.sock myproject.wsgi:application
[Install]
WantedBy=multi-user.target
and my nginx proxypass file looks like:
/etc/nginx/sites-available/myproject
server {
listen 80;
server_name server_domain_or_IP;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/usr/myproject;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/sammy/myproject/myproject.sock;
}
}
I can't seem to identify the error. Any help is appreciated. Thanks!