I am trying to get a legacy project I'm developing running in Homestead but I'm not familiar enough with nginx to get it working right. I know I can get this working in Apache with the following Alias:
Alias /path/to/project/api/public
<Directory /path/to/project/api/public>
Order allow,deny
Allow from all
# Rewrite
RewriteEngine On
RewriteBase /api
RewriteRule . index.php
</Directory>
I have succeed in getting the alias to mount correctly but I haven't managed to get the paths to write to the index.php file so /api/ gives me what I am expecting but /api/users gives a 404. When I tried adding something like rewite ^/api/(.*) /api/index.php?$1 break; I will get a 500 error and the log has
rewrite or internal redirection cycle while processing "/api/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/users", client: 192.168.10.1, server: project.local, request: "GET /api/users HTTP/1.1", host: "project.local"
"alias" cannot be used in location "/api/" where URI was rewritten, client: 192.168.10.1, server: project.local, request: "GET /api/ HTTP/1.1", host: "project.local"
server {
listen 80;
listen 443 ssl;
server_name project.local;
root "/home/vagrant/Code/project/public";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /api/ {
alias "/home/vagrant/Code/project/api/public/";
}
location ~ ^/api/(.+\.php)$ {
alias "/home/vagrant/Code/project/api/public/";
fastcgi_param SCRIPT_FILENAME $document_root$1;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
}