I'm using Laravel in a serverblock and I'd like to create an alias, for example /webmail. This results in an nginx "Primary script unknown
" error. I think I need to change my fastcgi_param
. Can anyone help me?
Below is the important part about my Nginx serverblock.
server {
listen 80 default_server;
server_name _;
set $root_path '/var/www/html/public';
root $root_path;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location /webmail {
root /var/www/;
}
}
So my webmail application is located in /var/www/webmail
.
Webmail works when I change the SCRIPT_FILENAME
to:
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
However, the root domain doesn't work anymore after this change. I can't place the line above in the location section.
Try this configuration:
So, we pass a different document root / script filename prefix to PHP depending on the location. On default locations we have
$root_path
set to/var/www/html/public
and on/webmail
we set it to/var/www
.You may need to add a separate
rewrite
/try_files
section in the/webmail
location, so thatindex.php
or any other default webmail entry script is tried. You need to look at your webmail's documentation for this.