Can't get server up and running digitalocean / django - django

I am very confused about how to set up my server because nothing seems to be working right. (I am a novice to all this)
I have the domain name dreamof.science with the registrar alp names. I have cloud hosting through digitalocean.
On digital ocean I have a droplet with nginx and django installed on my server through ssh on a secondary user (not root). There is an app I started from a book I am reading that teaches you django added onto it through my github in the directory sites/stratosphere.dreamof.science/source/django
I have been reading about this for days and the more I read the more I get confused. A records, AAA records, CNAMEs, PTR records, subdomains...I just want to know how the heck to get this server up and my app to run.
On my registrar I have my name servers pointed to the ones that digital ocean gave me for dreamof.science xx1.digitalocean.com xx2 etc.... On my registrar it also says I have 2 A records which all point to the same IP address which is the IP of my droplet. dreamof.science www.dreamof.science
I also have a CNAME to stratosphere.dreamof.science I am under the impression that this is my subdomain because you're not supposed to run apps on the regular domain....or something like that. Hence why I have my files in stratosphere.dreamof.science and nginx server config pointing towards stratosphere.dreamof.science
Now when I go to dreamof.science it just says "this webpage is unavailable." Same thing with stratosphere.dreamof.science and even when I just go directly to the server IP nothing shows up. I have the server running through the console on digital ocean and the droplet is active.
What is wrong here?

First, try creating a basic (empty) Django project in somewhere like /var/www/myproject. Start a debug server on port 8000 that accepts all connections using the runserver command like so:
python manage.py runserver 0.0.0.0:8000
Then navigate to http://dreamof.science:8000/ and see if you return a successful debug screen. That will tell you if the domain resolves correctly.
Now try setting a basic Nginx config, similar to the following:
server {
server_name dreamof.science;
listen 80;
location / {
proxy_pass http://localhost:8000;
}
}
Make sure that you don't have a firewall set to reject connections on that port.
Now try visiting http://dreamof.science/ to see if Nginx is running and set up to proxy the root domain to port 8000.

Related

Plausible analytics on a server with a webapp

I have Django hosted with Nginx on DigitalOcean. Now I want to install Plausible Analytics. How do I do this? How do I change the Nginx config to get to the Plausible dashboard with mydomain/plausible for example?
Setup plausible by either running the software directly or in a docker container - let's say it runs on port 8080
Then in your nginx.conf - you should have a server block for your domain
Within that add a location block with the path you want plausible on and add a proxy pass directive to forward the requests to localhost:8080
Monitor access.log and error.log to debug any issues that may happen

Access web server on VirtualBox/Vagrant machine from host browser?

I have a Django web server on a VirtualBox/Vagrant machine running Ubuntu.
I have followed this guide to create a Django project: https://docs.djangoproject.com/en/dev/intro/tutorial01/
I have a web server running at http://127.0.0.1:8000/ inside my guest machine. This is the first time I am running a Django web server. It is supposed to be a hello world app.
How can I access this web application from my host browser?
I have tried running ifconfig in the guest to get the IP that I should visit I found a promising IP address in inet addr.
But I have tried entering the following into my host browser and it didn't work.
http://inetaddrnumbers:8000/
How can I access the web server from my browser?
Try this.
Open the vagrant file (should be in the directory where you specified to create a new vagrant machine).
Search for config.vm.network. If you didn't setup the file earlier, it should be commented.
Change it to look something like this config.vm.network "private_network", ip: "55.55.55.5". Here ip address (55.55.55.5) can be any ip address you want.
Now logout from the vagrant machine and reload your vagrant machine by this command vagrant reload.
Again ssh to your vagrant machine and restart your django server by this command python manage.py runserver 0.0.0.0:80. Again the port address (80) can be 8000 if you want so.
After that, in your browser, enter the following address 55.55.55.5, and hopefully you should see your webapp.
Now if you would like to go further, you can edit your host file, and add this line
55.55.55.5 mynewdomain.com
Then in your browser, enter the follow address,
mynewdomain.com
And you should see your web app. Note that, www is not added in the domain name inside the host file, so only mynewdomain.com can be accessed. You can however add it.
Hope this helps. Cheers.
Complementing #Kakar answer, this configuration can also be done using this:
config.vm.network "private_network", type: "dhcp"
This will assign an IP automatically.
For further reading: https://www.vagrantup.com/docs/networking/private_network.html

Deploy app with dokku to default http port (80)

I have a problem having my application accessible through standard 8080 port on digital ocean. My DNS settings is:
example.com is linked to some completely different IP
api.example.com is linked to my digital ocean droplet IP.
My dokku instance VHOST file is set to "api.example.com" and HOSTNAME file also to "api.example.com". After I push my application to this dokku instance, the last line says "Application deployed: http://api.example.com". However even after this, my application is not accessible on api.example.com but only on api.example.com:49204.
I think I miss something but I don't know what, because I was not able to find a tutorial dealing with the exact strings that need to be configured for dokku.
dokku config:unset NO_VHOST
fixed the issue in my case

Configure Nginx To Accept Domain Name

I bought a Domain Name today, changed the DNS to match the exact VPS IP and configured Nginx to run my app.
So far, I can connect to my app using the external ip, from any computer, but I still can't connect to it via the Domain Name.
I've set the server_name to be the exact domain name I purchased, is there anything left I must do?
it is DNS configuration problem.
for sure about reason open putty and see output about site content by curl or wget or lynx.
example:
lynx mysite.com
if it work and returned proper result nginx config is true but it is DNS problem.
dns problems:
/etc/hosts
/etc/hostname
bad configuration
try ping sitename.com on your pc with ms dos. if has timeout then its not nginx problem.

Django app running in EC2, but trying to visit elastic URL returns page not found

I'm just starting out with EC2, and I've pulled down a git repo that I started on my local machine and so I know that it works running the server from there, and it seems to works when I run my server from the EC2 instance I have running, but for some reason, when I visit the elastic IP address of that instance I get a page-not-found. Any idea on why that might be?
So, I've now started using nginx, and made a conf file following the instructions here: https://code.djangoproject.com/wiki/DjangoAndNginx that is as follows:
server {
listen 80;
server_name ec2-54-242-149-154.compute-1.amazonaws.com;
access_log /var/log/nginx/USBag.access.log;
error_log /var/log/nginx/USBag.error.log;
location /basicMap/ {
alias /home/www/ec2-54-242-149-154.compute-1.amazonaws.com/basicMap/;
expires 30d;
}
location / {
include fastcgi_params;
fastcgi_pass 127.0.0.1:8080;
}
}
basicMap is a place that I have already defined in my django app, and the linked ec2 ip is the one my server is running on. I am having a lot of difficulty finding documentation on how to proceed or how to determine if my conf file is correct or not. Using the standard python manage.py runserver doesn't work however. Advice on how to proceed?
There is a lot of info about setting up a production django server out there, and I'll give you my personal preferences below, but before all that let's backup and see if we can just get any response from the production server.
To start the development server on your EC2 instance run:
manage.py runserver 0.0.0.0:8000
That command will cause runserver to bind to all interfaces and serve files to the external world. You'll never want to do this outside of development, but it is a good way just to test if your django app is setup before complicating things. Now try hitting your EC2 instance and see if you get a response.
If that's still not working, make sure you allow incoming connections to the server's port (8000 in the command above, 80 once live). You could test that you have ports open using netcat (nc -l).
Once you are satisfied that you have your app setup, I'd recommend you use nginx as your front end webserver and gunicorn as your django webserver in production. You'll likely want to look into setting up a virtualenv, supervisord etc for your production setup (here is a tutorial: http://senko.net/en/django-nginx-gunicorn/), but all that depends on the specifics of your project.