I need to configure nginx for different location on same domain for two php frameworks. example.com/ - codeigniter (root /var/www/html/codeigniter)
example.com/api - laravel 5.2 (root /var/www/html/laravel)
here my examples, but they not work.
server {
listen 80;
server_name example.com www.example.com;
root /var/www/html/codeigniter;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-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;
}
location /api {
root /var/www/html/laravel/public/;
index index.php index.html index.htm;
try_files $uri $uri/ index.php?$query_string;
location ~ \.php$ {
try_files $uri /index.php =500;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-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;
}
}
}
In first example perfectly works codeinginter on routes example.com/*, but laravel not work on route:
/api - codeigniter return 404 page not found,
/api/index.php - laravel return 404 because this page not exists,
/api/user/ -codeigniter also return 404 page
this config also not works:
server {
listen 80;
server_name example.com;
root /var/www/;
index index.php index.html index.htm;
charset utf-8;
access_log /var/log/nginx/example.com-access.log;
error_log /var/log/nginx/examplw.com-error.log error;
sendfile off;
client_max_body_size 100m;
location /api {
root /var/www/html/laravel/public;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
try_files $uri /index.php =500;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-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;
}
location ~ /\.ht {
deny all;
}
}
location / {
root /var/www/html/codeigniter;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-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;
}
location ~ /\.ht {
deny all;
}
}
}
this configuration also not work example.com - codeigniter works perfectly, example.com/api - codeigniter return 404 example.com/api/index.php - laravel return 404
Can anyone help me find the right way to configure this?