Results 1 to 15 of 15
  1. #1
    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

  2. #2
    It takes like 5 seconds to google for this answer...

  3. #3
    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.

  4. #4
    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. #5
    http://www.webhostingtalk.com/showthread.php?t=651393
    Lots of examples there.

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

    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. #6
    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. #7
    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. #8
    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. #9
    Join Date
    Jul 2011
    Posts
    381
    I don't think it is best way. I got to learn, should not give up!

  10. #10
    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. #11
    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. #12
    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. #13
    Join Date
    Jan 2012
    Posts
    4
    Hello,

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

    Beautiful document. See the.

  14. #14
    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. #15

    thanks

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

  16. Newsletters

    Subscribe Now & Get The WHT Quick Start Guide!

Similar Threads

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

Related Posts from theWHIR.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •