Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Nginx rewrite not working as expected

$
0
0
Here directories structure
http://localhost -> /usr/local/nginx/web/webroot
http://localhost/sess8283737/wordpress -> /usr/local/nginx/wordpress
http://localhost/sess244737/phpmyadmin-> /usr/local/nginx/phpmyadmin


I have below block, it works fine with index.html, but does not work when actual php files
when user visits http://localhost/sess8283737/wordpress and I want nginx to load files from /usr/local/nginx/wordpress
and set sess8283737 as variable

server {
listen 80;
server_name localhost;
root /usr/local/nginx/web/webroot;

location / {
root /usr/local/nginx;
if ($uri ~ "^/sess([a-z0-9]+)/(wordpress)") {
rewrite ^/sess([a-z0-9]+)/wordpress /wordpress/$2;
}

if ($uri ~ "^/sess([a-z0-9]+)/(phpmyadmin)") {
rewrite ^/sess([a-z0-9]+)/phpmyadmin /phpmyadmin/$2;
}

location \.php$ {
if ($uri ~ "^/sess([a-z0-9]+)/(wordpress)") {
rewrite ^/sess([a-z0-9]+)/wordpress /wordpress/$2;
}

if ($uri ~ "^/sess([a-z0-9]+)/(phpmyadmin)") {
rewrite ^/sess([a-z0-9]+)/phpmyadmin /phpmyadmin/$2;
}

include fastcgi.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}

}

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>