how do you get two webservers working on one machine?

Posted on

how do you get two webservers working on one machine? – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about apache-2.2, nginx, , , .

I want to host five websites on one VPS I just bought.

  1. a PHP site called
  2. a django site called
  3. phpmyadmin which will be
  4. phppgadmin, which will be
  5. and another django site called

All the django sites will be running with mod_wsgi in apache, and all the PHP sites will be running in nginx with fastcgi.

I’m a developer, not a sysadmin, so I’m having a hard time figuring out the best way to do this. The reason I’m running my PHP from nginx is because I don’t want to install mod_php, which allows me to use the worker MPM in apache.

Currently I have nginx running off of port 8080, and apache running off of port 80. When I go to it brings up the django site. When I go to, it brings up the PHP site.

Like I said before, I’m not a server person so this stuff is making my head spin. Is there any way to access stuff from nginx without specifying the port number in the URL?

Solution :

Basically when you put in “” the web browser actually goes to “” (port 80 is the default HTTP port).

You can only assign one application per port on a computer, so only one can listen to the default HTTP port (80) and the other will have to use another port.

There are three ways around this:

1) the proper way would be to use nginx as your main web server (i.e. listening on default http port 80), set Apache to listen on another port (e.g. 8080) then set up a ‘reverse proxy’ (google is your friend here). This is the ideal set up. It takes a bit more effort to configure but there are hundreds of guides out there that are really helpful.

2) use nginx to serve the django websites (if that is possible?)

3) a quick and easy way (although not recommended), assuming the PHP sites are for webmasters only and the django sites won’t need https, you could set up the PHP sites to run over HTTPS. That way you could have Apache running on port 80 (default HTTP) and nginx running on port 443 (default HTTPS). Just put ‘https://’ instead of ‘http://’ and you’ll get to port 443.

IMO, there is no need to run web applications on both web servers.

Due to the fact that I cannot find a good and reliable standalone fastcgi process manager, I would run both Django and PHP applications on Apache, using mod_wsgi for Django and mod_fcgid for PHP apps. The only thing I might consider running on a separate web service would be static files. Both nginx and lighttpd excel at serving static files. By “static files” I do not only mean images, stylesheets or javascript, but also static HTML pages generated by your web applications as part of a caching mechanism.

Regarding mod_php, this will not be needed, since you will be running PHP in fastcgi mode using mod_fcgid. This will also let you use the worker MPM (threaded).

I hope this gives you some pointers.

You’d better use apache as backend, with nginx proxy at port 80. Nginx can cache pages, and forward specific hosts to apache port 8080.

location / {
    proxy_pass        http://localhost:8000;
    proxy_set_header  Host       $host;
    proxy_set_header  X-Real-IP  $remote_addr;

Put them on different ports or IPs. Have one server listen on instead of, if it’s just for local development.

For public serving, I’d suggest just using fastcgi (fcgid if using apache) for everything. There’s really no need for all these replacements like wsgi; fastcgi is great, and much more flexible (in that you can run python2.5 and python3.1 and ruby side by side, for instance).

Leave a Reply

Your email address will not be published.