Symfony2 nginx issue - all pages 404 not found - php

I've got problem with my project in symfony2 when i'm trying to run this on nginx.
www.domain/ works fine
www.domain/app_dev.php ,"An error occurred while loading the web debug toolbar (404: Not Found).Do you want to open the profiler?"
www.domain/app.php/someurl/ - 404 not found
Is it server configuration issue or should I change my .htaccess in some way to make it possible to run with nginx?

You can check my dev config (with PHP-FPM):
server {
listen 80;
server_name dev.example.com;
root /var/www/web;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log error;
index app.php index.html index.htm;
try_files $uri $uri/ #rewrite;
location #rewrite {
rewrite ^/(.*)$ /app.php/$1;
}
location ~ \.php(/|$) {
# try_files $uri =404;
fastcgi_index app.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include 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;
fastcgi_buffer_size 1280k;
fastcgi_buffers 4 2560k;
fastcgi_busy_buffers_size 2560k;
}
location ~ /\.ht {
deny all;
}
}

Related

Laravel, Docker and Nginx: 404 for all files in /public folder

I created a new project in Laravel 7 by using docker-compose 3.3 and Nginx 1.17.
The enpoints created on Laravel works well, the problem comes when I try to access to whatever static asset in the '/public' folder. I tried with .css and .js files and also with the robots.txt but Laravel returns a 404 not found error.
This is my nginx.conf (taken from https://laravel.com/docs/7.x/deployment#nginx)
events {
}
http {
server {
server {
listen 80;
server_name localhost;
root /var/www/app/public;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass app:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
}
I tried different fixes found on forums and on Stackoverflow, like recompiling files, clear the cache... But nothing works.
Can you spot the problem?
can you try the following config:
server {
listen 80;
index index.php index.html;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}

wordpress nginx rewrite to wp-admin

I want to create dockerized Wordpress with nginx that will use /kokpit instead of /wp-admin I'm using nginx:latest container with default config. And declared my server block for Wordpress like below
server {
listen 443 ssl;
ssl_certificate /etc/nginx/localhost.crt;
ssl_certificate_key /etc/nginx/localhost.key;
server_name dimidia.dev.com;
root /var/www/html;
index index.php;
error_log /var/log/nginx/stderr_dimidia debug;
access_log /var/log/nginx/stdout_dimidia;
location /media
{
rewrite ^/media/(.+) /wp-content/themes/mytheme/$1;
}
location /
{
try_files $uri $uri/ /index.php?$args;
}
location /kokpit
{
rewrite ^/kokpit(.*) /wp-admin$1;
}
location ~ \.php$ {
fastcgi_read_timeout 300;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
client_max_body_size 50m;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_pass dimidia_php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
However when I reach to /kokpit files like load-scripts.php are returning 404 instead of scripts, and I cannot reach any php files inside kokpit (all are returning 404) big question is: why?

NGINX FASTCGI/PHP - Primary script unknown while reading response header from upstream, client

I have a development box that each user has a www folder in the home dir. NGINX is hosting those dirs from http://IP ADDRESS/USERNAME. And this works great. I want to get PHP working in the same fashion.
/etc/nginx/sites-available-default:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
#root /usr/share/nginx/html;
#index index.html index.htm;
# Make site accessible from http://IP ADDRESS/
server_name IP ADDRESS;
#location ~ ^/(.+?)(/.*)?$ {
location ~ ^/(.+?)(/.*)?$ {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
alias /home/$1/www$2;
index index.html index.htm index.php;
include /etc/nginx/php.fast.conf;
autoindex on;
}
php.fast.conf file:
location ~ \.php$ {
fastcgi_split_path_info ^(.+?\.php)(/.*)?$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /home/$1/www$2$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
As you can see I have tried a few variations but seem to continue to receive the following error in the log: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client.
When attempting to render a simple PHP info page The page displays "file not found"
Other info:
Server = ubuntu 14.x
Latest Nginx
Digital Ocean Droplet
Thanks in advance.
server {
listen 80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location ~* \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $fastcgi_script_name =404;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi_params;
}
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location ~* ^/(.+?)/www(/.*|/|)$ {
root /home;
index index.php index.html;
fastcgi_pass unix:/var/run/php5-fpm.sock;
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* ^/(.+?)(/.*|/|)$ {
index index.php index.html;
try_files $uri $uri/ #home;
}
location #home {
rewrite ^/([^/]+?)$ /$1/www/ last;
rewrite ^/(.+?)(/.*|/)$ /$1/www$2 last;
}
}
The cons of this config, you can't use URI like /<anything_you_want>/www.
Maybe it helps. But it's weird, non-optimized and ugly config.

Query strings in NGINX

I have problem with my configuration server on nginx.
My configuration:
server {
listen 80;
server_name shop.md;
index index.php index.html index.htm;
access_log /var/log/nginx/test.dev.access.log;
error_log /var/log/nginx/test.dev.error.log;
location / {
root /home/vagrant/Workspace/shop/web;
try_files $uri $uri/ app_dev.php /app_dev.php$is_args$args;
}
location ~ .php$ {
root /home/vagrant/Workspace/shop/web;
index index.html index.htm index.php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param APPLICATION_ENV development;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
}
sendfile off;
}
This configuration allow urls like this :
http://shop.md:8000/1/femei-pantofi
http://shop.md:8000/1/femei-pantofi?min_price=1&max_price=1000
For this URL:
http://shop.md:8000
I get the error 403 Forbidden
I use the #rewriteapp directive of nginx for my Symfony2 projects. The resulting configuration looks somewhat like this:
# strip app.php/ prefix if it is present
rewrite ^/app\.php/?(.*)$ /$1 permanent;
location / {
index app.php;
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
# pass the PHP scripts to FastCGI server from upstream phpfcgi
location ~ ^/(app|app_dev|adminer)\.php(/|$) {
fastcgi_pass phpfcgi-siyabonga;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
}
This works fairly well for me and is taken from the official nginx wiki page about Symfony2 with some additional changes. Also you should check the official Symfony2 docs. They have an example of a correct nginx configuration.

Laravel 4.1 on nginx routes error 404

I am having troubles with the routes of laravel on a nginx Server.
It shows a "404 not found" for all the routes, except for the default one, very similar to this problem: nginx configuration for Laravel 4
The solution to that problem:
server {
listen 80;
server_name sub.domain.com;
set $root_path '/srv/www/htdocs/application_name/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 ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /\.ht {
deny all;
}
}
it works well, the only problem is that i need the root_path to be /srv/www/htdocs because I have other projects running there to.
Whenever i change the line:
set $root_path '/srv/www/htdocs/application_name/public';
to:
set $root_path '/srv/www/htdocs';
the problem starts on url's like: localhost/application_name/public/users

Categories