I’ve been working on a project to create a Django based website. Over the weekend (Saturday I think) I tried to get it up and running on my Linode server. However, after a couple of failed attempts I decided to use the free hosting coupon1 I had for DigitalOcean to see if that allowed me to reply more easily deploy … the short answer … meh.
What I didn’t realize over the weekend is that while I had been trying to deploy my Django site, I had installed Nginx on my Linode server that was also running apache2. This lead to them both trying to listen on port 80 but because Nginx was the last thing I had kicked off, it was winning.
While I was working on my Django site I should have realized that something was up when I tried to connect to the blog for the site (still a WordPress site on my Linode server) and it returned a ‘Can not connect to the server message’. I didn’t pay much attention because I figured (incorrectly) that I had done something specific to that subdomain, and not that I had made all of the sites on my Linode server inaccessible.
Last night at about 9 I thought, “Well, it should’t take long for me to figure out the issue with the new blog. ”
By 10:15 I tried everything the internet had told me to try and I was still unable to get apache2 to reload.
I googled a bunch of stuff, but nothing was helping.
When I tried to get the status on apache2 I would get this:
● apache2.service - LSB: Apache2 web server Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: inactive (dead) since Tue 2018-05-01 05:01:03 PDT; 5s ago Docs: man:systemd-sysv-generator(8) Process: 7718 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS) Process: 7703 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS) May 01 05:01:03 milo apache2: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80 May 01 05:01:03 milo apache2: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80 May 01 05:01:03 milo apache2: no listening sockets available, shutting down May 01 05:01:03 milo apache2: AH00015: Unable to open logs May 01 05:01:03 milo apache2: Action 'start' failed. May 01 05:01:03 milo apache2: The Apache error log may have more information. May 01 05:01:03 milo apache2: * May 01 05:01:03 milo apache2: * Stopping Apache httpd web server apache2 May 01 05:01:03 milo apache2: * May 01 05:01:03 milo systemd: Started LSB: Apache2 web server.
This morning I started to google each line of the status message and finally got to this:
no listening sockets available, shutting down
Googling for that lead me to trying this:
sudo netstat -ltnp | grep ':80'
Which output this:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3324/nginx -g daemo tcp6 0 0 :::80 :::* LISTEN 3324/nginx -g daemo
And finally, I saw the issue. Over the weekend while I was futzing around I had apparently installed Nginx and let it listen on port 80 AND kept it running.
Once I killed the Nginx process with this:
sudo kill -9 3324
I was able to restart apache2 with no problems.
I find that when I mess something up like this it’s important to ask myself what I learned from the experience.
In that vein …
What did I learn from this experience?
- Can’t run apache2 and Nginx on the same server and have them listen on the same port. Seems obvious, but you know having to actually deal with it really seals the deal
- The output messages are super helpful … google each part of them and don’t give up
- A good night’s sleep can make all the difference
- Rolling your own web server is less expensive than having it be Turnkey (a la SquareSpace, or some other hosted solution) but you end up being your own Sys Admin and that’s actually pretty easy when things are going well, and a freaking nightmare when they’re not
- Thanks to the Talk Python to Me Course for Entrepreneurs ↩