Deploy app with dokku to default http port (80) - digital-ocean

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

Related

Nginx Proxy Manager and django with nginx

I have a stack Django+Gunicorn+nginx running in docker containers. It is accessible from outside by domain and Port, like web.example.com:1300 . Also, there is Nginx Proxy Manager (NPM) running (uses ports 80 and 443) and succesfully managing some other resources (for example nextcloud). But it doesn't proxy to my django project at port 1300, shows "502 Bad Gateway".
In the Proxy Hosts of NPM I've added config:
domain names: web.example.com
Forward Hostname / IP: nginx_docker_container_name (this way it works with other resources)
Forward Port: 1300
Other settings: tried multiple combinations without success (like with and without SSL certificates etc.)
Is it possible to proxy using NPM?
Sorry if I missed to write some information, actually I do not know what else to state.
I managed to solve the problem myself.
So, nginx in docker container serves web-site with static pages. Nginx proxy manager proxying htpp protocol to nginx and secures communication (and also works from docker container in my set-up).
My mistake was that I didn't connect those docker containers by virtual network.
Ones I put them into one network - everything works.
Then I unpublished nginx port (1300).
NPM proxy settings are "standard", e.g. no "custom location" and nothing in "Advanced" tab. Just "Forward Hostname / IP" is docker container tag and "Forward Port" is nginx port it listens to (80 by default).
With WhiteNoise , you don't need to configure nginx for django static files
❤️❤️❤️

How can I change django runserver url?

I'm trying to change django project url, so that users, who wants to connect to website in local area network will see url instead of localhost:8000 or 127.0.0.1. I need to change localhost:8000/users/board to be http://example.eu. I've tried to python manage.py runserver http://example.euand then thought about changing url's but it doesn't work. Also tried to change hosts file(Windows OS), but as far as I understand I need real ip address not url. Is it possible to do this thing and how?
You can use python manage.py runserver 0.0.0.0:8000. 0.0.0.0 means all IPv4 addresses on the local machine. So the server can be reachable by 127.0.0.1 and your private ip address like 10.10.5.8. So now others can access the server using http://10.10.5.8:8000. You the runserver on port 80, so that port can be removed from the url (by default is 80).
But to use any domain instead of ip, you have to change the hosts file of all the clients using the server to add domain to ip address mapping. Alternatively you can configure local network server to map the particular url to your system ip.
Run a local domain with the same port
Opening the /etc/hosts file on your mac with
sudo nano /etc/hosts
And for windows I believe you need to open:
C:\Windows\System32\Drivers\etc\hosts
In here add the domains you want, for example I added vazkir.com
....
127.0.0.1 localhost
127.0.0.1 vazkirtje.com
127.0.0.1 www.vazkirtje.com
.....
Lastly you can add it the domain to you ALLOW_HOSTS in your settings.py:
ALLOWED_HOSTS = ["localhost", "127.0.0.1", "vazkirtje.com", "www.vazkirtje.com"]
And now you can visit your Django application (with port 8000) at:
http://vazkirtje.com:8000
The solution is not perfect since you do have to specify the port you are using, but this does let you use a domain for your local Django application in a relatively easy manner;)
Run a local non-existent domain without specifying the port
If you do want to run it without specifying the port; so just vazkirtje.com then you can use port 80, because this is the default port for HTTP.
Make sure the domain you are testing does not exist, since the domain lookup will first be done on existing domains. So check if you get a similar message to the one I got on chrome, when visiting the url:
Now you can specify this port by adding port "80" to the "runserver" command. You only do need to use "sudo" to run the command at this port, since you need admin rights for this. So run:
sudo python manage.py runserver 80
And now you should be able to access your Django application by visiting:
http://vazkirtje.com

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

Can't get server up and running digitalocean / 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.

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.