0

I did some extensive searching and there are quite a few posts on nginx proxy_pass questions. I've tried modifying my problem to some of those questions with out any progress so here goes.

I'm in the midst of rewriting a php based website into Rails. The original site itself is simple 2 pages with forms. It uses a mod_rewrite / mod_proxy solution in Apache to mask the url of where the site continues after form post.

the php site has 3 directories that have nothing but 3 .htaccess files in them for simplicity sake lets call the directories a, b, c. each .htaccess file with the following

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ http://www.domainbeingpostedto.com/actual_letter_directory/$1 [P,L]
</IfModule>

I'm not an apache expert but I'm pretty sure the [P,L] is same as proxy_pass and last in nginx?

I'm trying to rewrite this solution for the php site that was converted into a rails cms using passenger and nginx instead.

The solution I have so far is not working because the rails app just returns a 404 with the page not found, so I know proxy_pass isn't forwarding the post request to the other server. What I have for my nginx.conf file is:

server {
    listen 80;
    server_name newtestappdomain.com;

    location /a/ {
        proxy_pass http://www.domaintoacceptdatapostandbemasked.com/;
        #rewrite ^/a/(.*)$ http://www.domaintoacceptdatapostandbemaskedcom/a/ last;
    }

    location /b/ {
        proxy_pass http://www.domaintoacceptdatapostandbemasked.com/;
        #rewrite ^/b/(.*)$ http://www.domaintoacceptdatapostandbemasked.com/b/ last;
    }

    location /c/ {
        proxy_pass http://www.domaintoacceptdatapostandbemasked.com/;
        #rewrite ^/c/(.*)$ http://www.domaintoacceptdatapostandbemasked.com/c/ last;

    }

    root /home/deploy/testapp/public;   # <--- be sure to point to 'public'!
    passenger_enabled on;

}

If I uncomment out the rewrite rule, it just bounces to the other site which i'm trying to mask. I did a header trace to verify as well. Didn't see anything post to the other domain. I'm kind of stumped as I'm really new to nginx and not sure what to do. Apache doesn't work well with rails and mod_rewrite / mod_proxy. Any insight would be great.

toucansam
  • 3
  • 1
  • 2

1 Answers1

1
proxy_pass http://www.domaintoacceptdatapostandbemasked.com/;

This rule would be proxy requests to "/" location (leading slash in proxy_pass uri) (a/, b/ and c/ would be lost).

Just use uri without leading slash and it should work perfect

proxy_pass http://www.domaintoacceptdatapostandbemasked.com;

If you need to change uri, you can use rewrite before proxy_pass. for example:

location /a/ {
    rewrite /(a/.*)$ /actual_letter_directory/$1 break; # as from you .htaccess example
}
CyberDem0n
  • 14,545
  • 1
  • 34
  • 24