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;
}
}
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 trying to run my django project on subdomain, my nginx configuration is,
server {
listen 80;
server_name subdomain.example.me www.subdomain.example.me;
location /static/ {
root /home/gagan/webmash/blog;
}
location /media/ {
root /home/gagan/webmash/blog;
}
location / {
include proxy_params;
proxy_pass http://my_ip:9000;
}
}
While my supervisor configuration is,
[program:webmash]
command=/home/gagan/webmash/env/bin/gunicorn --workers 3 --bind unix:/home/gagan/webmash /blog/blog.sock blog.wsgi --env DJANGO_SETTINGS_MODULE=blog.settings.production
directory=/home/gagan/webmash/blog
autostart=true
autorestart=true
stderr_logfile=/var/log/saporawebapp.err.log
stdout_logfile=/var/log/saporawebapp.out.log
when i run supervisor using,
sudo supervisorctl restart webmash
It doesn't show any error. On restarting nginx, it too doesn't show any error.But my project is not runing either at https://subdomain.example.com or my_ip:9000.
What can be the possible causes for such behaviour
I recommend Nginx with systemd over supervisor.
Here's a tutorial to leave Django running with Nginx + Gunicorn + Systemd + AnaConda.
Maybe my github here will help you:
Githhub/Nginx
I'm trying to deploy a Django app in a Ubuntu Server 18.04 using Nginx and Gunicorn. Every tool seems to work properly, at least, from logs and status points of view.
The point is that if I log into my server using SSH and try to use curl, gunicorn is able to see the request and handle it. However, if I write directly my IP, I get simply the typical Welcome to nginx home page and the request is completely invisible to gunicorn, so it seems nginx is unable to locate and pass the request to the gunicorn socket.
I'm using nginx 1.14.0, Django 2.2.1, Python 3.6.7, gunicorn 19.9.0 and PostgreSQL 10.8.
This is my nginx config
server {
listen 80;
server_name localhost;
location /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias /home/django/myproject/myproject;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
And these are my gunicorn.sock
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
and gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=django
Group=www-data
WorkingDirectory=/home/django/myproject/myproject
ExecStart=/home/django/myproject/myproject/myproject/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
MyProject.wsgi:application
[Install]
WantedBy=multi-user.target
I've been following this guide (https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04), where most of all has worked as expected, but with the difference that my project is not a completely new one as in the tutorial, but cloned from my git repo (however, it's tested and the code works properly)
I was expecting the Django admin to be accessible from my browser already with this config, but it's not. I try to access my IP from my browser and I get Welcome to nginx but also 404 if I visit /admin. In addition, the gunicorn logs shows no requests.
In the other hand, if I log through SSH into my server and I execute curl --unix-socket /run/gunicorn.sock localhost, I can see in the gunicorn logs the request done by curl.
Any help is welcome.. I've been here for hours and I'm not able to get even 1 request from outside the server.
PD: it's also not something related to the ports in the server, since when I access the root of my IP, I receive the nginx answer. It just seems like Nginx has no config at all.
in your nginx config, you should use your proper server_name instead of localhost
server_name mydomain.com;
If not, you will fall back to the default nginx server, which returns the "welcome to nginx" message. You can change which virtual server is default by changing the order of servers, removing the nginx default, or using the default_server parameter. You can also listen to multiple server names.
listen 80 default_server;
server_name mydomain.com localhost;
If the Host header field does not match a server name, NGINX Plus routes the request to the default server for the port on which the request arrived. The default server is the first one listed in the nginx.conf file, unless you include the default_server parameter to the listen directive to explicitly designate a server as the default.
https://docs.nginx.com/nginx/admin-guide/web-server/web-server/#setting-up-virtual-servers
Remember that you have to reload the nginx config after making changes. sudo nginx -s reload for example.
Finally, I've got it working properly. You were right about the config of nginx, although my real problem was not to delete/modify default config file for nginx in sites_enabled folder. Thus, when I was setting listen 80 default_server I got the following error
[emerg] 10619#0: a duplicate default server for 0.0.0.0:80 in
/etc/nginx/sites-enabled/mysite.com:4
Anyway, I had a problem with the static files which I still not knowing why it works like that. I needed to set DEBUG = True to be able to see static files of the admin module.
I'll keep on investigating the proper way of serving static files in production for the admin panel.
Thank you so much for the help!
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!