I’m currently working on an NGINX configuration for a symphony application. I’m trying to set up a rule where any request to /app should be served by app.php. However, I’m having some trouble getting this to work.
Here’s my current configuration:
server {
listen 81;
server_name *.host.com;
port_in_redirect off;
access_log /var/log/nginx/_access.log;
error_log /var/log/nginx/_error.log;
root /var/www/html/web;
index index.php index.html index.htm;
location / {
# try to serve file directly, fallback to rewrite
try_files $uri @rewriteapp;
}
location @rewriteapp {
# rewrite all to app.php
rewrite ^(.*)$ /app.php/$1 last;
}
# PHP-FPM configuration
location ~ [^/].php(/|$) {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param HTTP_PROXY "";
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
With this configuration, I’m expecting that when a user navigates to http://*.host.com/app, NGINX should serve the app.php file. However, this is not happening.
Any help or guidance would be greatly appreciated. Thank you in advance!
Shivanesh Lal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.