LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   NGINX + Apache (http://www.linuxquestions.org/questions/linux-software-2/nginx-apache-4175438884/)

Rafael25 11-27-2012 05:23 AM

NGINX + Apache
 
Hi,

Can I have Apache and NGINX on the same server ?

If yes, can it be run on the same port ?

In this case one of the service will be put off. So, how do I switch the services using a PHP code. Is it possible ?

Thanks in advance.

Turbocapitalist 11-27-2012 07:16 AM

You might be able to run them on the same port if they are bound to different hostnames or ip numbers. What are you trying to do?

Rafael25 11-29-2012 01:50 AM

Hi,

I want to run one service at a time i.e either NGINX or Apache so binding them to the same port wont cause any issues I feel.

I wish to learn as to how do I switch those services through a PHP code ? I mean Apache service be put off and NGINX started and vice versa.

Thanks in advance.

Turbocapitalist 11-29-2012 03:00 PM

What version of what distro are you using? Regardless of whether you are using Upstart or System V, you could make a custom line in /etc/sudoers to allow the designated user to start and stop Apache and nginx. Then that can be called via a script.

headrift 11-29-2012 03:27 PM

I think you'd need a "switch_to_apache.php" served by Nginx, and a "switch_to_nginx.php" served by Apache, each with code to kill the running service and start the other.

But, unless you're low on resources and the server can only run one at a time, that's the hard way to do it. I'd run both at the same time with Nginx on port 8080 or whatever and only for specific files / directories and then use Apache's mod_rewrite to redirect requests for those files to the Nginx port.

Rafael25 11-30-2012 05:15 AM

Quote:

Originally Posted by Turbocapitalist (Post 4839756)
What version of what distro are you using? Regardless of whether you are using Upstart or System V, you could make a custom line in /etc/sudoers to allow the designated user to start and stop Apache and nginx. Then that can be called via a script.

Hi,

Thanks for the reply.
I am using a CentOS 6.3 x86 machine. I installed NGINX and PHP-FPM through yum. I am able to run a file say index.php located at /home/user/www/index.php

Now, how do I handle this case:
The file located at /home/user/www/index.php should through an internal server error if it has the group and owner set to "root" and function smooth if the group and owner set to "user"

Any help is greatly appreciated. Thanks in advance.

Rafael25 11-30-2012 05:16 AM

Quote:

Originally Posted by headrift (Post 4839765)
I think you'd need a "switch_to_apache.php" served by Nginx, and a "switch_to_nginx.php" served by Apache, each with code to kill the running service and start the other.

But, unless you're low on resources and the server can only run one at a time, that's the hard way to do it. I'd run both at the same time with Nginx on port 8080 or whatever and only for specific files / directories and then use Apache's mod_rewrite to redirect requests for those files to the Nginx port.

Hi,

Thanks a lot.

I have figured a way out to handle this. I prefer doing it manually for now.
I am stuck with the permissions stuff now as I mentioned in my above post. Please suggest.

headrift 11-30-2012 11:48 AM

Quote:

Originally Posted by Rafael25 (Post 4840055)
Now, how do I handle this case:
The file located at /home/user/www/index.php should through an internal server error if it has the group and owner set to "root" and function smooth if the group and owner set to "user"

Best way to do that is to have Nginx not run as root (you probably shouldn't be running it as root anyway), and make the files not readable by "user"... permissions 640 or something similar when owned by root in the root group. It will error out because the server won't be able to read the file.

Things will work fine if the file is owned by "user" with permissions 755 or 644, depending. Just basic user and permission rights here. *shrug*


All times are GMT -5. The time now is 01:17 PM.