Chp 8: Nginx config issue

246 views
Skip to first unread message

ntm112294

unread,
Jan 12, 2017, 10:01:58 PM1/12/17
to Obey the testing goat! Test-Driven Web Development with Python book
I'm on my second time through attempting to use an Ubunti 16.04 droplet through digitalocean. Both times I have successfully reached the point where I see the "Nginx it works!" webpage at my staging domain.

My issue occurs when attempting to establish communication between nginx and django.

In the "Adjusting the Database Location" section I am successfully able to rearrange the filesystem.

In the "Creating a Virtualenv manually, and using requirements.txt" section I successfully install Django and run the Django server with no errors.

At this stage I believe that I have followed all steps correctly. My file structure looks as such:
/home/frodo
     |--- sites
     |     |--- staging.nickmorton.me
│   │    ├── database
│   │    │     └── db.sqlite3
│   │    ├── source
│   │    │    ├── manage.py
│   │    │    ├── superlists
│   │    │    ├── etc...
│   │    │
│   │    ├── static
│   │    │    ├── base.css
│   │    │    ├── etc...
│   │    │
│   │    └── virtualenv
│   │         ├── lib
│   │         ├── etc...
│   │
│   ├── www.staging.my-website.com
│   │    ├── database
│   │    ├── etc...
Following along in the " Simple Nginx Configuration" section I add a file inside of /etc/nginx/sites-available entitled staging.nickmorton.me with the following text:

server {

    listen 80;

    server_name staging.nickmorton.me;

    location / {

        proxy_pass http://localhost:8000;

    }

}

after linking this file to /etc/nginx/sites-enabled and removing the default from sites-enabled my directories are in the following state:
|--- etc
|    |--- ngingx
|    |    |--- sites-available
|    |    |    |--- default staging.nickmorton.me
|    |    |--- sites-enabled
|    |    |    |--- staging.nickmorton.me
On the command line I run: ps aux | grep nginx
as well as: ps aux | grep manage
Just to be sure that there are no active instances of Django or nginx.
Then I run the following
: sudo systemctl start nginx
: sudo systemctl reload nginx
Then I run ../virtualenv/bin/python3 manage.py runserver
and the Django server spins up without an error.
When I go to view the webpage in a browser (tried chrome and firefox) at staging.nickmorton.me (also tried just using the ip address) I get the following error: ERR_CONNECTION_REFUSED

Running sudo nginx -t does not detect any nginx config errors.
The nginx error log does seem helpful, reading as follows: (note that I'm on EST and it is only 1/12/17 today, could the problem be caused by the systems date/time config?)

2017/01/13 01:49:02 [notice] 5572#5572: signal process started

2017/01/13 01:49:22 [notice] 5582#5582: signal process started

2017/01/13 01:54:14 [notice] 5631#5631: signal process started

2017/01/13 02:48:11 [notice] 5730#5730: signal process started

I tried to be painstakingly specific here in hopes that someone with a better eye may spot an error somewhere along this process, or perhaps there is an advisable path to pursue in an effort to resolve this piping issue.

ps Thanks for a great book Harry, enjoying it so far and feeling very motivated to truly deploy the project!

Harry Percival

unread,
Jan 13, 2017, 3:38:18 AM1/13/17
to ntm112294, Obey the testing goat! Test-Driven Web Development with Python book

Hmmm. Connection refused is strange. If nginx is working but it cant talk to django for whatever reason, you usually see 504 bad gateway. Connection refused feels like the request isnt even making it to nginx...  did you ever see the default nginx "welcome to nginx" page?  Have you tried rebooting? Could therre be any sort of firewall in the way?


--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

--
Harry Percival
+44 78877 02511

lmt...@columbia.edu

unread,
Mar 18, 2017, 9:23:00 PM3/18/17
to Obey the testing goat! Test-Driven Web Development with Python book, ntm1...@gmail.com
Hi there,

I ran into the same problem this afternoon. It seems the created symbolic link was broken, once I recreated it using absolute paths (it was not broken anymore), I got a 502 bad gateway NginX response instead of the "Unable to connect", an expected failure :). Once I manage.py runserver, my website was finally deployed!

I take this opportunity to thank you Harry, the book is great! 

(As a note, I also spent some time figuring out why I couldn't start nginx on a rasp. It seems there is a built in process already listening to port 80 preventing nginx from doing so. It worked once I killed this unknown process, it could be useful to other developers)
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-goat-book+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages