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;
}
}
Related
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
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;
}
}
I am using AWS ROUTE 53 to resolve my website domain name. I am able to launch my website with domain name (domain_name.com). However, when I prefix 'www' to the domain name, its opening only the default nginx page
My ROUTE 53 configuration:
MY nginx configuration:
server {
listen 80;
server_name www.schoolnskill.com, schoolnskill.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root <path_to_my_django_project>;
}
location / {
include proxy_params;
proxy_pass http://unix:<path_to>/gunicorn.sock;
#proxy_pass http://unix:<path_to>/gunicorn.sock
}
}
Based on the comments.
Both http://schoolnskill.com/ and http://www.schoolnskill.com/ work now, after fixing the server_name. The issue was caused by comma in:
server_name www.schoolnskill.com, schoolnskill.com;
Removing the comma was the solution:
server_name www.schoolnskill.com schoolnskill.com;
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;
}
}
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;
}