mattPark
mattPark

Reputation: 31

nginx on raspberry pi

I followed http://chimera.labs.oreilly.com/books/1234000000754/ch08.html#_simple_nginx_configuration to install a nginx server on my raspberry pi to work with my django project. I added a file /etc/nginx/sites-available/pi:

server {
    listen 80;
    server_name pi;

    location /static {
        alias /home/pi/sites/pi;
    }

    location / {
        proxy_pass http://localhost:8000;
    }
}

However, "pi" from my browser does not work, instead i still have to use the raspberrypi ip address. and after i changed my settings.py file in my django project,

DEBUG = False

TEMPLATE_DEBUG = DEBUG

ALLOWED_HOSTS = ['pi']
[...]

the ip address of the raspberry pi does not work anymore. Please help.

Upvotes: 3

Views: 563

Answers (2)

David Francos Cuartero
David Francos Cuartero

Reputation: 193

Completing André Rainho answer.

You're correctly configuring django and exposing it to your network.

The thing is, it's not all you need. One of the main pilars of the internet is domain name resolution, that being the system that converts domain names to internet addresses. Have a look at its wikipedia page: https://en.wikipedia.org/wiki/Domain_Name_System

Ok, so what now? Well, you have multiple options:

Editing etc/hosts

Edit your /etc/hosts file on your client machines (on linux, %SYSTEMDIR%/drivers/etc/hosts on windows) and add the following line to it:

"<your_ip> pi"

Configuring a local DNS server

You could install a DNS server on the PI (see, for example, this post), then add to your pi /etc/hosts:

"<your_ip> pi"

And finally configuring either your router to send the pi's IP as DNS server or your computers to use the pi's IP as DNS server, up to you.

ZeroConf

I really don't like the ZeroConf approach usually, but hey, it's there. ZeroConf is a "Zero Configuration" system that broadcasts services offered by machines running it.

So, installing ZeroConf in the pi and getting a ZeroConf client on your PC would automatically make you be able to see the service.

Conclusions

IMHO, if you have only a few machines and you don't mind guests not seeing your django service, I'd use /etc/hosts solution. Give it a try and don't forget to configure the pi with static IP.

Upvotes: 1

arainho
arainho

Reputation: 35

You could use pi.local instead of pi, for this to work you need Zeroconf on the Raspberry Pi and your Laptop.

On the raspberry pi install avahi, you can find details on how to do it here on elinux.org wesite

On the Laptop in case of windows you need Bonjour Print Services, in case of Mac OS X you have Bonjour by default, in case of Linux you need Avahi / Zeroconf installed.

Finally you need to update the allowed hosts on Django settings to this

ALLOWED_HOSTS = ['pi.local']

Upvotes: 1

Related Questions