I'm an Nginx beginner, I'm found a frustrating situation.
I have a php app that worked just fine on localhost, but after I moved it to a VPS server routing is broken - all urls render the main page. My nginx config:
server {
listen 80;
server_name mysite.me;
root /var/www/html;
index index.php index.html index.htm;
# Add additional types
include mime.types;
location /cockpit {
try_files $uri /cockpit/index.php?$args;
index index.php index.html index.htm;
}
location / {
try_files $uri /index.php$args;
index index.php index.html index.htm;
}
location ~ \.php(/|\?|$) {
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_split_path_info ^(.+\.php)(.*)$;
# fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param COCKPIT_URL_REWRITE On;
include fastcgi_params;
}
location ~ .sqlite$ {
deny all;
}
location /api {
proxy_pass http://localhost:8889;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;.
proxy_cache_bypass $http_upgrade;
}
location /banki {
alias /var/www/banki;
try_files $uri $uri/ /index.html last;
}
}
and my php routing is
$app->get("/", function($params) use($app, $twig) {
$collection = cockpit('collections')->findOne('posts');
$type_collection = cockpit('collections')->find('Type');
$template = $twig->load('index.twig');
if ( $collection) {
$posts = cockpit('collections')->find('posts');
}
return $template->render([
'posts' => $posts,
'types' => $type_collection,
]);
});
$app->bind("/:type", function($params) use($app, $twig) {
$collection = cockpit('collections')->findOne('posts');
$type_collection = cockpit('collections')->find('Type');
$template = $twig->load('category.twig');
if ( $collection) {
$posts = cockpit('collections')->find('posts');
}
return $template->render([
'type' => $params['type'],
'posts' => $posts,
'types' => $type_collection,
]);
});
I used Google to look at a lot of ideas, but none have worked for me.
I know that this is not an issue with app itself, because if I run apache2 at port 8080 and go to mysite.me:8080 app works as expected.
Moreover, /cockpit location works fine.
Can anyone help?