Configurations of Django application deployed on DigitalOcean - django

I have a little trouble such as: I've created a Django application and deployed it on DigitalOcean via Nginx, Unicorn. Everything works very well with an IP address. But now I've bought a domain address and set it to my application. After this trouble has come. I can't open my admin dashboard on my computer, application is not opening on my phone, but opens on friend's phone, and so on. I just want to know, are my configurations right for replacing IP address with domain name ?
settings.py:
ALLOWED_HOSTS = ['134.209.39.229','challengers.az']
nginx:
server {
listen 80;
server_name challengers.az;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/username/project;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/username/myproject.sock;
}
}

Related

Django project working on IP address of droplet. But, it does not work on custom domain

I have my domain on GoDaddy and my hosting setup in DigitalOcean. So after I setup my basic django project, I used a droplet to deploy the code to an IP address. When I run this command, my project was running at my [IP_ADDRESS]:8000:
gunicorn -w 2 -b 0.0.0.0:8000 --chdir /home/USER_NAME/projectdir/test_project test_project.wsgi
Then, I put the three digital ocean nameservers in GoDaddy. I also modified the settings.py file by using the ALLOWED_HOSTS variables:
ALLOWED_HOSTS = ['IP_ADDRESS', 'www.DOMAIN_NAME', 'DOMAIN_NAME']
My Nginx configuration looks something like this:
server {
listen 8000;
listen 80;
server_name IP_ADDRESS DOMAIN_NAME www.DOMAIN_NAME;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/USER_NAME/projectdir;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
But still, I get 'This Site can't be reached'. I also checked that the nameservers have been updated by using https://lookup.icann.org/en. So I don't know where the problem lies. If you need any additional information let me know. Thank you

Nginx subdomain running the wrong web application

so I have a ubuntu server that run two different website with two different domain:
www.firstwebsite.com
www.secondwebsite.com
But when I create an AAA record to create a subdomain with the first domain (like this)
demo.firstwebsite.com
If I go to this subdomain it automatically run the application website of my other domain (www.secondwebsite.com)
I tried creating a specific socket&service file for the subdomain for it but it still run the web application of the second domain.
Im not sure what is causing that and how to fix that? thank you
nginx config file
server {
listen 80;
server_name firstwebsite.com;
return 301 $scheme://www.firstwebsite.com$request_uri;
}
server {
listen 80;
server_name www.firstwebsite.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /var/www/firstwebsite;
}
location /media/ {
root /var/www/firstwebsite;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/firstwebsite.sock;
}
}

Using domain name for Django application deployed on DigitalOcean

I've created a django application, deployed it on DigitalOcean, and everything works and looks well when using website via IP address. Now I've bought a domain and want to use it for my application, but don't know what to do. First of all I've added my domain name to ALLOWED_HOSTS in settings.py, then DigitalOcean's DNS servers added to site where I bought domain. But app doesn't work via domain name yet. Here are my codes:
settings.py:
ALLOWED_HOSTS = ['64.225.1.249', 'forexample.az']
nginx:
/etc/nginx/sites-available/myproject
server {
listen 80;
server_name my_ip_address (not domain, maybe here I should write domain name ?);
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/my/_username//myproject;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/my/_username/myproject.sock;
}
}

Need help on connecting django to react using nginx and gunicorn

I'm trying to connect Django back-end to a React build provided to me by the front-end developer. I'm using Gunicorn for Django and Web server is Nginx.
The below config file is a result of extensive Googling.
Currently Django back-end works on port 80/8000 but whenever I change the port to anything else like 8001 below, the server does not respond.
The complete thing is running on Google Ubuntu VM.
I've executed sudo ufw disable for testing purposes.
server {
#listen 80;
listen 8001;
listen [::]:8001;
server_name xx.xx.7.xx;
location = /favicon.ico {
access_log off;
log_not_found off;
}
location /static/ {
root /home/username/cateringm;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
#location / {
# try_files $uri $uri/cm_react_build/build/index.html; # this is where you serve the React build
# }
}
server {
listen 8002;
listen [::]:8002;
server_name xx.xx.7.xx;
root /home/username/cm_react_build/build;
index index.html index.htm;
location /static/ {
root /home/username/cm_react_build/build;
}
location /test {
root /home/username/cm_react_build/build;
index index.html;
try_files $uri $uri/ /index.html?$args;
}
}
I'm new to configuring web servers. Help would be appreciated.
I found the problem. Google by default blocks all ports except port 80. I updated the firewall rules for different ports and the requests were going through.

Connecting to website via domain redirects to IP(no guides nor "fixes" helped)

I am using GoDaddy domain and connectiong it to django+gunicorn+nginx droplet hosted on DigitalOcean.
After all tried configs of DO, nginx, etc., I'm still getting the same result.
When I'm trying to connect via domain, it changes it to IP address and proceeds...
Last nginx config I stopped on is:
server {
listen 80;
server_name example.com www.example.com ip.ip.ip.ip;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/user/webapp;
}
location /media/ {
root /home/user/webapp;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/user/webapp/webapp.sock;
}
}
Removing IP completely from nginx conf results in same behavior but instead of getting Django webpage I'm getting redirected to nginx default webpage and the domain is again changed to IP.
Try using this statement
location \homepage {
rewrite ^ http://$host$request_uri? permanent;
}