Home NGINX and htaccess URL rewrite
Reply: 0

NGINX and htaccess URL rewrite

Dipraj Kuwar
1#
Dipraj Kuwar Published in 2018-01-10 18:02:05Z

I have a web application ( built using Laravel 5.5 framework ) hosted on WAMP and apache runs on http. The WAMP is behind NGINX and domain name points to NGINX, basically I have NGINX as proxy to APACHE.

I am using that web application code as generic and dedicated instance with urls like below for multiple clients.

https://www.testapp.com/ClientK123/
https://www.testapp.com/ClientK456/
https://www.testapp.com/ClientK789/
https://www.testapp.com/ClientK1011/

A web app instance can have a specific or dedicated directory like ClientK123 & ClientK456 in apache webroot like below

C:\wamp\htdocs\ClientK123\
C:\wamp\htdocs\ClientK456\ 

Similarly more than 1 web app instance can share common code i.e. generic instance and same is available as

c:\wamp\htdocs\ClientKGeneric\ 

I have the mod_rewrite module enabled on APACHE and the rewrite rules for dedicated instances ( ClientK123 and ClientK456 ) are working as expected, but when I try to point some instance ( https://www.testapp.com/ClientK789/ and https://www.testapp.com/ClientK1011/ ) at generic code ( 3rd htaccess Rewrite Condition ) it is doing 307 redirect to the Generic folder with changing the url in the browser to https://www.testapp.com/ClientKGeneric/ But when I tried to access ClientK789 or ClientK1011 using browser on server ( where I have WAMP configured ) with local host http://127.0.0.1/ClientK789/ or http://127.0.0.1/ClientK1011/ it worked as expected.

Following are the contents of apache .htaccess file

RewriteEngine on 
RewriteBase /

## ClientK2610 
RewriteCond %{REQUEST_URI} ^.*ClientK123/(.*$) [NC]
RewriteRule ^(.*)$ /ClientK123/%1 [QSA,END]

## ClientK2611 
RewriteCond %{REQUEST_URI} ^.*ClientK456/(.*$) [NC]
RewriteRule ^(.*)$ /ClientK456/%1 [QSA,END] 

## ClientKGeneric Generic Codebase - For ClientK789 and ClientK1011
RewriteCond  %{REQUEST_URI} /ClientK(\d+)/(.*$) [NC]
RewriteRule ^(.*)$ /ClientKGeneric/%2 [QSA,L]

Following are the NGINX configuration extracts ( 10.30.40.24 is the private IP of WAMP server )

location /ClientK123 {
        proxy_pass http://10.30.40.24;
        proxy_connect_timeout   1800;
        proxy_send_timeout              1800;
        proxy_read_timeout              1800;
        send_timeout                    1800;
        proxy_redirect off;
        proxy_buffering off;
        proxy_set_header                Host                    $host;
        proxy_set_header                URI                     $uri;
        proxy_set_header                Referer                 $http_referer;
        proxy_set_header                X-Real-IP               $remote_addr;
        proxy_set_header                X-Forwarded-For         $proxy_add_x_forwarded_for; 
}

location /ClientK456 {
        proxy_pass http://10.30.40.24;
        .
        .
        .
}

location /ClientK789 {
        proxy_pass http://10.30.40.24;
        .
        .
        .
}

location /ClientK1011 {
        proxy_pass http://10.30.40.24;
        .
        .
        .
}

I ahve checked NGINX and APACHE logs but no 307 redirect traces available, not sure what I am missing or have done anything wrong here.

Please assist.

Thanks, :)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.296287 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO