hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Software and Control Panels : NGINX reverse proxy to apache - Settings?
Reply

Forum Jump

NGINX reverse proxy to apache - Settings?

Reply Post New Thread In Hosting Software and Control Panels Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 01-22-2012, 05:20 AM
agriz agriz is offline
Aspiring Evangelist
 
Join Date: Jul 2011
Posts: 381

NGINX reverse proxy to apache - Settings?


Hi

I have installed both in centos using yum.
Now i have changed the httpd listen to 127.0.0.1:8080

I don't run any virtual hosts.
How do i setup nginx config to work with apache?
How do i make sure the reverse proxy is working?

Thanks



Sponsored Links
  #2  
Old 01-22-2012, 05:42 AM
Grumps Grumps is offline
Web Hosting Master
 
Join Date: May 2005
Posts: 1,074
It takes like 5 seconds to google for this answer...

  #3  
Old 01-22-2012, 05:44 AM
agriz agriz is offline
Aspiring Evangelist
 
Join Date: Jul 2011
Posts: 381
so cute.
That is why i mentioned i am not using any virtual hosts.
I have many links from google everything is dealing with virtual hosts.

Sponsored Links
  #4  
Old 01-22-2012, 06:17 AM
agriz agriz is offline
Aspiring Evangelist
 
Join Date: Jul 2011
Posts: 381
I am getting "HTTP/1.1 403 Forbidden"
Is that right?

from this link (http://www.webconfs.com/http-header-check.php)

index.html was missing in the root document.
after uploading, i am getting "HTTP/1.1 200 OK =>"

is nginx handling the site? No reverse proxy ?

  #5  
Old 01-22-2012, 06:32 AM
Grumps Grumps is offline
Web Hosting Master
 
Join Date: May 2005
Posts: 1,074
http://www.webhostingtalk.com/showthread.php?t=651393
Lots of examples there.

and more reference:
http://wiki.nginx.org/HttpProxyModule

Quote:
I am getting "HTTP/1.1 403 Forbidden"
Is that right?
I don't really know what behavior you wanted...

You should also be sure to set the root as default nginx root is different from your apache root. For example, in your nginx.conf, write
root /var/www/html;
insider server { ... }


Also, from your browser. Open firebug or developer tools in opera/chrome. You can see the full header information from there better than some web tool. You should see nginx as the engine.

  #6  
Old 01-22-2012, 06:47 AM
agriz agriz is offline
Aspiring Evangelist
 
Join Date: Jul 2011
Posts: 381
nginx has different values in the root.
I changed it to

Nginx after changed
root /var/www/html

Apache Document Root is /var/www/html (not changed. Files are here.)

Is that correct?

  #7  
Old 01-22-2012, 07:00 AM
agriz agriz is offline
Aspiring Evangelist
 
Join Date: Jul 2011
Posts: 381
PHP Code:
#######################################################################
#
# This is the main Nginx configuration file.
#
# More information about the configuration options is available on
#   * the English wiki - http://wiki.nginx.org/Main
#   * the Russian documentation - http://sysoev.ru/nginx/
#
#######################################################################

#----------------------------------------------------------------------
# Main Module - directives that cover basic functionality
#
#   http://wiki.nginx.org/NginxHttpMainModule
#
#----------------------------------------------------------------------

user              nginx;
worker_processes  2;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


#----------------------------------------------------------------------
# Events Module
#
#   http://wiki.nginx.org/NginxHttpEventsModule
#
#----------------------------------------------------------------------

events {
    
worker_connections  4096;
}


#----------------------------------------------------------------------
# HTTP Core Module
#
#   http://wiki.nginx.org/NginxHttpCoreModule
#
#----------------------------------------------------------------------

http {
    include       /
etc/nginx/mime.types;
    
default_type  application/octet-stream;

    
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"'
;

    
access_log  /var/log/nginx/access.log  main;

    
sendfile        on;
    
#tcp_nopush     on;
    
tcp_nodelay     on;

    
#keepalive_timeout  0;
    
keepalive_timeout  65;

    
gzip  on;

    
#
    # The default server
    #
    
server {
        
listen      80;
        
server_name  domain.com www.domain.com;

        
#charset koi8-r;

        #access_log  logs/host.access.log  main;

       # location / {
           # root   /usr/share/nginx/html;
           # index  index.html index.htm;
       #}
        
location / {
                
proxy_pass http://127.0.0.1:8080/;
                
proxy_redirect off;
                
proxy_set_header Host $host;
                
proxy_set_header X-Real-IP $remote_addr;
                
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                
proxy_connect_timeout 90;
                
proxy_send_timeout 90;
                
proxy_read_timeout 90;
                
client_max_body_size 10m;
                
client_body_buffer_size 128k;
                
proxy_buffer_size 4k;
                
proxy_buffers 4 32k;
                
proxy_busy_buffers_size 64k;
                
root /var/www/html;
                
index index.html index.htm index.php;
        }

        
error_page  404              /var/www/html/404.html;
        
location = /404.html {
            
root   /var/www/html;
        }

        
# redirect server error pages to the static page /50x.html
        #
        
error_page   500 502 503 504  /50x.html;
        
location = /50x.html {
            
root   /var/www/html;
        }

        
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
        
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|wav|bmp|rtf|js)$ {root /var/www/html;}
    }

    
# Load config files from the /etc/nginx/conf.d directory
    
include /etc/nginx/conf.d/*.conf;


This is the configuration.
But it seems there is some problem on this.

ip.address/some.html -- always throws 404 error
ip.address/some.php -- works good.
ip.address/img/ --- displays all the images. But apache was hiding that folder with Option -Indexes

  #8  
Old 01-22-2012, 08:01 AM
BreakFree BreakFree is offline
Junior Guru
 
Join Date: Nov 2011
Location: Johnson City, TN
Posts: 182
Personally, if you're not completely sure on how to setup and use NGINX and Apache, I would suggest using something that would automate the setup for you. While it doesn't setup Apache, it does automatically setup everything else for you and it works pretty well. It's simply, the the menu-based GUI is pretty simple to follow.

http://centminmod.com/

All you need is a clean CentOS install (minimal preferred) and SSH access. From there the CentminMod works wonders.

  #9  
Old 01-22-2012, 08:37 AM
agriz agriz is offline
Aspiring Evangelist
 
Join Date: Jul 2011
Posts: 381
I don't think it is best way. I got to learn, should not give up!

  #10  
Old 01-22-2012, 08:46 AM
BreakFree BreakFree is offline
Junior Guru
 
Join Date: Nov 2011
Location: Johnson City, TN
Posts: 182
Quote:
Originally Posted by agriz View Post
I don't think it is best way. I got to learn, should not give up!
If you're not familiar with setting up NGINX + Apache, or it's configuration, it would be one of the best methods to get you up and running without hours of researching or waiting for someone to post bits and pieces here and there.

The script builds everything from source, so it will take a little bit of time to install, though it is all automated. You will still, however, need to have some basic knowledge as if you require a more advanced setup, you'll still have to work with the setup and therefore, would still be learning.


The difference between what you have and the CentminMod is that it will provide you with a working example of an NGINX setup that you can do with as you please.

  #11  
Old 01-22-2012, 09:30 AM
agriz agriz is offline
Aspiring Evangelist
 
Join Date: Jul 2011
Posts: 381
It seems to be working good now.
I just have a doubt.

How does Nginx send php requests to apache from the above config?
Which line does the trick?

Or does it send request to apache to handle file types which are not "jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|wav|bmp|rtf|js" ?

In apache access log, I dont see anything expect php It is really a good sign.

  #12  
Old 01-22-2012, 05:35 PM
Grumps Grumps is offline
Web Hosting Master
 
Join Date: May 2005
Posts: 1,074
Quote:
Originally Posted by agriz View Post
How does Nginx send php requests to apache from the above config?
Which line does the trick?
this:
proxy_pass http://127.0.0.1:8080/;

in more detail,
location /
will match EVERYTHING (else). And then the above line passes it to your proxy.

things like .jpg will be caught by the latter statement.

  #13  
Old 01-24-2012, 05:45 PM
webrobat webrobat is offline
Temporarily Suspended
 
Join Date: Jan 2012
Posts: 4
Hello,

http://www.cyberciti.biz/faq/rhel-li...load-balancer/

Beautiful document. See the.

  #14  
Old 01-25-2012, 04:14 AM
gplhost gplhost is offline
Web Hosting Master
 
Join Date: Aug 2004
Location: Shanghai
Posts: 1,449
Quote:
Originally Posted by agriz View Post
i am not using any virtual hosts.
Why?

Thomas

__________________
GPLHost:>_ open source hosting worldwide (I'm founder, CEO & official Debian Developer)
Servers & our leading control panel and our Xen VPS hosting, which are already included in Debian and Ubuntu
Available in: Kuala Lumpur, Singapore, Sydney, Seattle, Atlanta, Paris, London, Barcelona, Zurich, Israel

  #15  
Old 01-25-2012, 05:44 PM
euroservers euroservers is offline
Newbie
 
Join Date: Jan 2012
Posts: 14
thanks

I saw useful information to set up Nginx. This thread worked for me too. The first time I installed nginx.

Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
[ Hiring ] Nginx Reverse Proxy / Centos/whm/cPanel Server Expert WickedWebsites Employment / Job Offers 5 10-25-2011 06:38 PM
Nginx cpanel pluginand apache settings hostyourdream Hosting Software and Control Panels 2 01-09-2011 06:35 PM
[help] nginx as reverse proxy for multimedia files dewaforex Hosting Security and Technology 1 12-12-2010 07:51 PM
Nginx in front of apache and prefork settings hostyourdream Hosting Software and Control Panels 1 11-30-2010 03:53 AM
nginx reverse proxy? PirateSolutions Hosting Security and Technology 3 11-22-2010 01:37 PM

Related posts from TheWhir.com
Title Type Date Posted
Nginx to be Included in Upcoming Ubuntu Release Web Hosting News 2014-01-08 15:17:12
Apache Market Share Falls in Netcraft October Web Server Survey Web Hosting News 2013-10-04 14:34:11
Apache Market Share Dips Slightly in June Netcraft Web Server Survey Web Hosting News 2013-06-06 13:40:21
Apache Loses 9.9 Million Sites in Netcraft April 2013 Web Server Survey Web Hosting News 2013-04-03 14:42:33
NGINX 1.2.0 Update of Web Server Improves HTTP Proxy Support Web Hosting News 2012-04-24 16:47:23


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?