1

Struggling to adapt nginx to my framework and get the equivalent of, in apache config :

Alias /site1 "/home/framework/public_HTML" 

(and then localhost/site1 displays site1 with local/dev settings thanks to $_SERVER['REQUEST_URI'])

What I have now with nginx :

server { listen localhost:80; server_name localhost; root /home/framework; index /public_HTML/index.php; location /site1 { # alias /home/framework/public_HTML/; # index index.php; # try_files $uri $uri/ =404; # try_files /home/framework/public_HTML/index.php =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.1-fpm.sock; } location ~ /\.ht { deny all; } } 

-> whether I comment in or out the lines in location /site1, all or none, adding removing trailing slash all around... => transparent redirect to localhost/site1/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/ (as copied from the url in the browser)

So, with everything commented out as it is shown, the correct index.php is getting the request & i'm getting a response but the url in the url bar and the $_SERVER['REQUEST_URI'] passed by nginx to my index.php file becomes

 /site1/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/ 

Why this loop ?

1 Answer 1

0

(forgot to answer with the solution I found at that time)

Unsure why it was looping before serving something, but my understanding in alias & index was biased by my use of them with apache & probably at the origin of the bug. What i did at the end to transition from apache alias to nginx servers was to use regex to have all my aliases as just one declared server so they easily point to the same folder & I don't have to worry about nginx config when creating a new project :

server { server_name "~^({[a-z]}2\.)*(?<project>\w+)\.(.*)localhost$"; root /home/framework/public_html; location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.1-fpm.sock; } location ~ /\.ht { deny all; } } 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.