The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

backen mod_perl httpd proxied through front end plain httpd

Discussion in 'General Discussion' started by anup123, Sep 9, 2004.

  1. anup123

    anup123 Well-Known Member

    Joined:
    Mar 29, 2004
    Messages:
    897
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    This Planet
    Hi.

    I would need to shift all /perl requests to backend mod_perl server.
    I have compiled mod_proxy as DSO in cPanel's httpd default installation.
    I have also compiled the backend httpd (httpd_perl)

    I have following directives in front end httpd for the virtual host:

    ProxyPass /perl/ http://localhost: port/perl/
    ProxyPassReverse /perl/ http://localhost: port/perl/

    Things do work only in following case:

    If the script ends is a .cgi and .pl but no query string after that. The back end and front end logs show that the ProxyPass And ProxyPassReverse is working

    However, the moment there is a qeuery string the ProxyPass doesn't seem to work and the front end error_log shows :

    File Not Found proxy:http://somedomain: port/perl/script.cgi?querystring.

    Can someone help on this please?
    httpd and httpd_perl are on same server but ports 80 and 82

    TIA
    Anup
     
    #1 anup123, Sep 9, 2004
    Last edited: Sep 11, 2004
  2. anup123

    anup123 Well-Known Member

    Joined:
    Mar 29, 2004
    Messages:
    897
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    This Planet
    Hi.

    Well to see if cpanel httpd install is responsible for mod_proxy not working, i tried it the other way around

    compiled http on a different prefix=....
    made it to listen to other port

    Then used it as proxying to the port 80 httpd where the mod_perl enabled httpd (cpanel) is running. Everything worked. The only difference is that with this hand compiled httpd, all modules were as DSO whereas in cpanel a lot of it goes as statically compiled.

    So is that cpanel (easyapache) built httpd would not let me run mod_proxy?
    Also, is there a way that from easyapache also, all the modules are as DSO instead of having it statically built. In fact when i had tried mod_perl in easyapache as statically compiled it never really worked. On building it as DSO it worked like charm

    Word from cpanel or users who have been able to use mod_proxy with easyapache built httpd would be welcome.

    TIA
    Anup
     
  3. anup123

    anup123 Well-Known Member

    Joined:
    Mar 29, 2004
    Messages:
    897
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    This Planet
    Problem is broken mod_gzip which would not let mod_proxy + mod_gzip work together.

    Anup
     
  4. computerworld

    computerworld Member

    Joined:
    Nov 25, 2004
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Hi Anup123, I have a regular Linux (CentOs3.3) & cpanel (9.9.8 C-146) based server with mod_proxy and mod_gzip and other regular modules. I can view the installed modules by typing:

    /usr/local/apache/bin/httpd -l

    I have configured another server for mod_perl where mod_status, mod_access, mod_userdir is integrated. I can view the installed

    modules by typing:

    /usr/local/httpd_perl/bin/httpd_perl -l

    I have opened the port: 8000 for the backend mod_perl enabled server. I also added this port in my firewall (apf) setting. So, this port is

    not blocked.

    My problem is that - when I try to run a script from /perl directory. I get a (404 - File not found) page in the browser and see the following in the backend server logs (/usr/local/httpd_perl/logs/error_log)

    I tried to run the script with (http://www.mydomain.com/perl/test.pl) or without proxy enabled (http://www.mydomain.com:8000/perl/test.pl).

    I disabled it from my frontend httpd.conf file when running the script without proxy. I also disabled mod_gzip through out the whole process.

    I only added the following configuration in my backend httpd.conf file

    What am I doing wrong here? I hope that you can shed some light and help me get going.
     
  5. computerworld

    computerworld Member

    Joined:
    Nov 25, 2004
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    I also noticed that I am getting the following errors in both backend and frontend of the apache status.


    ./apachectl status

    cat /usr/local/apache/logs/error_log

    cat /usr/local/apache/logs/access_log

    I am not sure, if it was like this or it just started happening due to some misconfiguration. I can view the status on other services though.
     
  6. anup123

    anup123 Well-Known Member

    Joined:
    Mar 29, 2004
    Messages:
    897
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    This Planet
    Keep everything (mod_cgi and mod_perl scripts) under cgi-bin

    Alias /perl/ ...... takes care of mod_perl
    ScriptAlias /cgi-bin/ ..... takes care of mod_cgi

    This way it's easier migrating from mod_cgi to mod_perl or vice versa if anything in mod_perl breaks. There is no directory such as /perl on server.

    Presuming that you are doing it this way too, in your frontend httpd do you have:

    Alias /perl/ /home/someusername/public_html/cgi-bin/
    In the VirtualHost section for mydomain.com?

    Also, once you have yr setup done, i would prefer to have backend port blocked for public access and be accessible from only front-end httpd.

    Anup
     
  7. computerworld

    computerworld Member

    Joined:
    Nov 25, 2004
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Thank you Anup123. I added the following lines in my backend httpd.conf

    I added the following lines in my frontend httpd.conf

    I added the line (Alias /perl/ /home/someusername/public_html/cgi-bin/) in the virtual host as per your suggestion but still getting the same error message. Is there any other configuration that I have been missing? I am sure that the mod_perl and mod_proxy is installed and the perl directory (/usr/local/httpd_perl/perl) is also created with proper permission. I also created perl directory in the userend (/home/public_html/someusername/perl). I put some scripts in the cgi-bin (for running with regular perl) and some scripts (for running with mod_perl) in the perl directory. So, it is a configuration problem either in the frontend or in the backend httpd.conf file.

    I must be missing something. I have one question though - are you talking about handling all scripts by mod_perl in the CGI-BIN directory? I thought that all the scripts in CGI-BIN will be handled by regular perl and the scripts in the PERL directory will be handled by MOD_PERL. So, does it mean that if I enable mod_perl for a customer and put all the scripts in CGI-BIN then all his scripts will be handled by mod_perl. I am sorry for my ignorance. I hope that you can help me fix this issue.
     
  8. anup123

    anup123 Well-Known Member

    Joined:
    Mar 29, 2004
    Messages:
    897
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    This Planet
    perl directory not needed. Refer to:
    http://theory.uwinnipeg.ca/modperl/docs/1.0/guide/config.html#Alias_Configurations

    Presume that you are running mod_perl script under mydomain.com
    So in the backend httpd you would have to have a VirtualHost container for mydomain.com with following included:
    <VirtualHost>
    ......
    ......
    <IfModule mod_perl.c>
    Alias /perl/ /home/mydomain/public_html/cgi-bin/
    PerlModule Apache::Registry
    <Location /perl>
    SetHandler perl-script
    PerlHandler Apache::Registry
    PerlSendHeader On
    Options +ExecCGI -Indexes
    </Location>
    </IfModule>
    ......
    ......
    </VirtualHost>

    Also in the backend httpd you must be having the following:

    <IfModule mod_perl.c>
    Alias /perl/ /usr/local/apache-perl/cgi-bin/
    PerlModule Apache::Registry
    PerlRequire /usr/local/apache-perl/conf/startup.pl
    PerlPostReadRequestHandler My::ProxyRemoteAddr

    <Location /perl>
    AllowOverride None
    SetHandler perl-script
    PerlHandler Apache::Registry
    Options ExecCGI -Indexes
    PerlSendHeader On
    </Location>
    </IfModule>

    Be watchful about the order of startup.pl and the line that follows thereafter.
    Following should be there in the startup.pl file:

    use Apache::Constants ();
    sub My::ProxyRemoteAddr ($) {
    my $r = shift;

    # we'll only look at the X-Forwarded-For header if the requests
    # comes from our proxy at localhost
    return Apache::Constants::OK
    unless ($r->connection->remote_ip eq "127.0.0.1")
    and $r->header_in('X-Forwarded-For');

    # Select last value in the chain -- original client's ip
    if (my ($ip) = $r->headers_in->{'X-Forwarded-For'} =~ /([^,\s]+)$/) {
    $r->connection->remote_ip($ip);
    }

    return Apache::Constants::OK;
    }

    1;


    I learnt all my stuff from here:
    http://theory.uwinnipeg.ca/modperl/docs/1.0/guide/scenario.html

    And BTW, the backend httpd when i do httpd-l i just get:

    Compiled-in modules:
    http_core.c
    mod_so.c
    suexec: enabled;

    Hope this makes it clear. Statically compiled modules could be a pain from maint point of view so i went with DSO route for the backed, so at least i do not have to reompile the whole thing when i need to upgrade mod_perl.

    Don't be in a hurry ... step by step and it should be up and running :)

    Anup
     
    #8 anup123, Nov 27, 2004
    Last edited: Nov 27, 2004
  9. computerworld

    computerworld Member

    Joined:
    Nov 25, 2004
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Thank you Anup, I couldn't get it working so far - I tried to do everything as per your guideline. I was also follwing the same website that you pointed out but couldn't get the job done - I guess I am too lazy to read the whole thing. Anyway, I am getting the following error (virtual host requires suexec wrapper...) in backend server's error log - when I restart it and still getting the 404 page. What am I missing now? Or is there any other steps that you forgot to mention? Thank you for your help...
     
  10. anup123

    anup123 Well-Known Member

    Joined:
    Mar 29, 2004
    Messages:
    897
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    This Planet
    Hello.

    When you access the backend from browser say:

    http://mydomain.com:port/perl/mypercript.cgi then does it work?

    Please Test it on a VirtualHost and see. To make things still clearer, example stuff given below:

    Front End httpd conf exmple:

    <VirtualHost xx.xx.xx.xxx>
    ....
    ....
    <IfModule mod_proxy.c>

    ProxyPass /perl/ http://mydomain.com:port/perl/
    ProxyPassReverse /perl/ http://mydomain.com:port/perl/

    </IfModule>
    .....
    .....
    </VirtualHost>

    Same Host in backend:

    <VirtualHost xx.xx.xx.xxx>
    ServerAlias ............
    ServerAdmin ..............
    DocumentRoot /home/mydomain/public_html
    ServerName www.mydomain.com
    User mydomain
    Group mydomain
    #CustomLog domlogs/mydomain.com combined
    <IfModule mod_perl.c>
    Alias /perl/ /home/mydomain/public_html/cgi-bin/
    PerlModule Apache::Registry
    <Location /perl>
    SetHandler perl-script
    PerlHandler Apache::Registry
    PerlSendHeader On
    Options +ExecCGI -Indexes
    </Location>
    </IfModule>

    </VirtualHost>

    port is port number on which the backend runs (82 for example)
    mydomain is the user group for mydomain.com

    Take care that the other things mentioned in my earlier post is also taken care of.
    Nope i haven't missed any detail. Just go thru the details in that earlier link again and again. It's the document which got me do it on my own. Yes it's indeed a Painful Learning Process ... but there are unfortunately no shortcuts in good things ;)

    Spend another week on this and i am sure you would ultimately get things to work. BTW, have mod_gzip disabled in your front end. It would not work with mod_proxy as mod_gzip is broken.

    Hope this helps.
    Anup
     
Loading...

Share This Page