LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-27-2012, 04:23 AM   #1
Rafael25
Member
 
Registered: Jul 2012
Posts: 53

Rep: Reputation: Disabled
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.
 
Old 11-27-2012, 06:16 AM   #2
Turbocapitalist
Member
 
Registered: Apr 2005
Distribution: Ubuntu, Debian, OS X (bsd)
Posts: 147

Rep: Reputation: 28
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?

Last edited by Turbocapitalist; 11-27-2012 at 06:18 AM.
 
Old 11-29-2012, 12:50 AM   #3
Rafael25
Member
 
Registered: Jul 2012
Posts: 53

Original Poster
Rep: Reputation: Disabled
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.
 
Old 11-29-2012, 02:00 PM   #4
Turbocapitalist
Member
 
Registered: Apr 2005
Distribution: Ubuntu, Debian, OS X (bsd)
Posts: 147

Rep: Reputation: 28
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.
 
Old 11-29-2012, 02:27 PM   #5
headrift
Member
 
Registered: Sep 2005
Distribution: Gentoo, Sabayon, Puppy, Arch
Posts: 165

Rep: Reputation: 29
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.
 
Old 11-30-2012, 04:15 AM   #6
Rafael25
Member
 
Registered: Jul 2012
Posts: 53

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
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.
 
Old 11-30-2012, 04:16 AM   #7
Rafael25
Member
 
Registered: Jul 2012
Posts: 53

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by headrift View Post
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.
 
Old 11-30-2012, 10:48 AM   #8
headrift
Member
 
Registered: Sep 2005
Distribution: Gentoo, Sabayon, Puppy, Arch
Posts: 165

Rep: Reputation: 29
Quote:
Originally Posted by Rafael25 View Post
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*
 
  


Reply

Tags
apache, nginx


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
uninstall apache for nginx ggalan Linux - Newbie 1 01-29-2012 12:54 AM
Apache optimization with nginx Ricky Linux - Server 1 11-14-2011 12:22 PM
Apache rewrites to nginx taara Linux - Newbie 2 03-14-2011 10:07 AM
LXer: Configuring Apache and Nginx LXer Syndicated Linux News 0 07-22-2010 11:10 AM
Nginx like as a reverse proxy for Apache Abadon_ Linux - Server 0 11-13-2009 04:53 AM


All times are GMT -5. The time now is 06:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration