I followed the Tutorial on Digital Ocean and installed LEMP server successfully.

Then I read about reverse-proxy using Nginx and APache for hosting multiple websites on the same droplet .

Since I have Big fat droplet , I would like to host two Laravel Based APP on the same droplet .

So using this tutorial I Installed apache2 LINK

But unluckily apache is not running

$ sudo service apache2 reload
 * Reloading web server apache2                                               *
 * Apache2 is not running

So I did

 sudo netstat -tlpn

and got this table

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         Stat     e       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LIST     EN      5377/nginx
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LIST     EN      1233/sshd
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LIST     EN      3529/mysqld
tcp6       0      0 :::80                   :::*                    LIST     EN      5377/nginx
tcp6       0      0 :::22                   :::*                    LIST     EN      1233/sshd

I am a windows user and I have no Idea about how to fix this .

Can any one help me out .

Thanks,

Nginx runs on port 80 and that's ok. The default port for the Apache httpd is port 80, too and that's a problem.

Reconfigure Apache httpd

  • Use port 8080 for your Apache httpd. Open ports.conf

    sudo nano vi /etc/apache2/ports.conf
    

    and replace

    Listen 80
    

    with

    Listen 8080
    

    Do the same for virtual hosts, if necessary.

  • Restart Apache httpd

    sudo systemctl restart apache2
    

    or on Trusty with

    sudo service apache2 restart
    
  • Check the output of netstat

    $ sudo netstat -tulpn | grep apache2
    tcp6   0  0 :::8080   :::*  LISTEN  22769/apache2
    

    And yes, also with the output above, httpd is listening on tcp port 80.

  • Reconfigure nginx to work as proxy and use your Apache httpd as backend, e.g. for port 80 by editing of /etc/nginx/sites-available/default

    sudo nano /etc/nginx/sites-available/default
    

    and add the proxy settings below in the location section

    proxy_pass http://127.0.0.1:8080;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto http;
    proxy_set_header X-Forwarded-Port 80;
    proxy_set_header Host $host;
    
  • Restart nginx

    sudo systemctl restart nginx
    

    or on Trusty with

    sudo service nginx restart
    
  • Check the output of netstat

    $ sudo netstat -tulpn | grep -P 'nginx|apache2'
    tcp  0  0 0.0.0.0:80  0.0.0.0:*  LISTEN  22973/nginx -g daem
    tcp6 0  0 :::80       :::*       LISTEN  22973/nginx -g daem
    tcp6 0  0 :::8080     :::*       LISTEN  22769/apache2 
    

And it's a good idea to configure httpd to listen only on 127.0.0.1.

  • As an nginx expert, this is the way to go about it, temporarily stop nginx, install Apache, change Apache to be on a different port, start nginx. :) – Thomas Ward Jan 13 '16 at 16:44
  • @ThomasW. Yes, of course. :) But it's really necessary to stop nginx to install httpd? – A.B. Jan 13 '16 at 16:47
  • 1
    Out Of The Box Installations of both Apache and nginx autodefault to Port 80 for "Out Of The Box" functionality. There's no way around it - whether Apache or Nginx is installed first, you have to shut one off for apt-get to work right and configure the thing, then change one to be on a different port and start the other one. Otherwise you get fail to configure issues. – Thomas Ward Jan 13 '16 at 16:52
  • @ThomasW. I did not stop nginX while I was trying to install apache2 I think There is some error in that , Can you tell me how I can Roll back everything and do a fresh install ? – Vikram Jan 14 '16 at 5:54
  • Why a fresh install? – A.B. Jan 14 '16 at 6:50

Long story short - you have to run apache listening on different port (Listen), since port 80 is already in use by nginx.

  • This is the VERY basic explanation of what's going on; it would help if you gave an actual solution or method to fix this, rather than just say what the conflict is. – Thomas Ward Jan 13 '16 at 22:34

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.