0

I'm a web developer servicing multiple clients. With Ubuntu 16.04 on my local laptop, how would I create a batch script so that I can toggle between using NGINX and Apache Web Server smoothly so that I could install both but only fire up the web server daemon I need on a given project? I do realize, however, that I'd have to have an .htaccess in some cases on one, and a regex config on the other (because of no .htaccess). I also realize that I'd have to install the website under both /etc/*/sites-enabled.

Note also that I set me.com in my /etc/hosts to 127.0.0.1. So, I'd be toggling what responds on me.com, unless you know of a way that I can have both running at the same time but have ng.com respond from the nginx, and ap.com respond from the apache.

  • 2
    Can't you use a reverse proxy like haproxy (or nginx itself can be one)? Also, alternately you can make then listen on different ports, or different interface in case of multiple interfaces. There are so many options... – heemayl Apr 24 '17 at 3:17
  • ^Seconded. I'd use nginx as a reverse proxy. – muru Apr 24 '17 at 3:29
0

Use the reverse proxy technique through NGINX. (SOURCE)

So, one site that is enabled could be ng.com for stuff to run through NGINX on my developer laptop, and then one site that is enabled in NGINX called ap.com could be the reverse proxy that points to Apache on 8080 instead of 80. Then, I configure Apache to respond on 8080 for that ap.com domain.

The trick in the nginx file are these lines:

proxy_set_header X-Real-IP  $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;

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.