In the browser, I get "File not found". Server log and configuration are provided. I'm really not sure what to do at this point.
The Error:
2018/04/24 14:00:46 [error] 28717#28717: *9 FastCGI sent in stderr:
"Primary script unknown" while reading response header from upstream,
client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1",
upstream: "fastcgi://127.0.0.1:9000", host: "wasob.localhost"
wasob.localhost
server {
#Nginx should listen on port 80 for requests to yoursite.com
listen 80;
server_name wasob.localhost;
#Create access and error logs in /var/log/nginx
access_log /var/log/nginx/default.access_log;
error_log /var/log/nginx/wasob.error_log error;
root /var/www/html/wasob/;
#The homepage of your website is a file called index.php
index index.php;
location / {
try_files $uri $uri/ index.php
}
#Specifies that Nginx is looking for .php files
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
#if (!-f $document_root$fastcgi_script_name) {
# return 404;
#}
fastcgi_index index.php;
# SCRIPT_FILENAME parameter is used for PHP FPM determining
# the script name. If it is not set in fastcgi_params file,
# i.e. /etc/nginx/fastcgi_params or in the parent contexts,
# please comment off following line:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY "";
# include the fastcgi_param setting
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}
}
The error and config are available at https://gist.github.com/skinuxgeek/4d4f86490f87805d1781782670551db9
Related
Im learning NGINX, so any help is really appreciated.
I have the frontend of a website running as the root of mysite.com, and now I want to run wordpress from mysite.com/blog.
My file structure is:
/srv/mysite/frontend
/srv/mysite/wordpress
this is the error i've been getting from the nginx logs
2020/03/29 00:09:03 [error] 23049#23049: *39 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: XXXXXXX, server: www.mysite.com, request: "GET /api HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "mysite.com"
and this is my nginx config file so far
listen 80 default_server;
server_name www.mysite.com mysite.com;
charset utf-8;
location ^~ /blog {
root /srv/mysite/wordpress;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
location / {
root /srv/mysite/frontend/dist;
try_files $uri /index.html;
}
}
This error message shows either the wrong path of the sock file or the permissions. Make sure the php sock file exists in the path /run/php/php7.2-fpm.sock and change the permissions of the file.
For Debian
chown -R wwww-data:www-data /run/php/php7.2-fpm.sock
For Rhel
chown -R nginx:nginx /run/php/php7.2-fpm.sock
Also, you can try this config.
location /blog {
root /srv/mysite/wordpress;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
I have an nginx config for my server as follow, I want
when I request service/dev/sync/sync
it will route to /home/work/app-web/src/api/dev/sync.php/sync
match the php rule with $fastcgi_script_name is /dev/sync.php and $fastcgi_path_info is sync
this rule only need for ~ /service/([a-zA-Z]*/[a-zA-Z]*)(/[a-zA-Z]*)$.
But when I request /service/dev/sync/sync, it will return 404 with error
*173 open() "/home/work/nginx/html/dev/sync.php/sync" failed (2: No such file or directory), client: 172.18.17.90, server: localhost, request: "POST /service/dev/sync/sync HTTP/1.1"
/home/work/nginx/html is the default root for my nginx server. the root config is not
work at all.
what's the problem with this config?
server {
set $work_dir /home/work/app-web;
listen 80;
server_name localhost;
location ~ /service/([a-zA-Z]*/[a-zA-Z]*)(/[a-zA-Z]*)$ {
root $work_dir/src/api;
set $file $1;
set $action $2;
try_files $uri $uri/ /$file.php$action$is_args$query_string;
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)/(.*)$;
fastcgi_pass unix:/home/work/app-web/php/var/run/app-web.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $work_dir/src/api$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param UNIQUE_ID $request_id;
include fastcgi_params;
}
}
}
Root config works fine.
Your problem is that there is an internal redirection to /dev/sync.php/sync?, and the new inner-url does not match the regexp-location
You can activate the debug with
error_log /var/log/nginx/debug.log debug;
The logs look like this :
*1 trying to use file: "/dev/sync.php/sync" "/home/work/app-web/src/api/dev/sync.php/sync"
*1 internal redirect: "/dev/sync.php/sync?"
*1 rewrite phase: 1
*1 http script value: "/home/work/app-web"
*1 http script set $work_dir
*1 test location: ~ "/service/([a-zA-Z]*/[a-zA-Z]*)(/[a-zA-Z]*)$"
*1 using configuration ""
The new URL is /dev/sync.php/sync?, and this url matches with no location, because the regexp /service/([a-zA-Z]/[a-zA-Z])(/[a-zA-Z]*)$ is not intended for the inner-URL.
I suggest you another configuration :
server {
set $work_dir /home/work/app-web;
listen 80;
server_name localhost;
location ~ /service/([a-zA-Z]*/[a-zA-Z]*)(/[a-zA-Z]*)$ {
root $work_dir/src/api/;
set $file $1;
set $action $2;
rewrite .* /src/api/$file.php$action last;
}
location ~ \.php {
internal;
root $work_dir;
fastcgi_split_path_info ^(.+\.php)/(.*)$;
fastcgi_pass unix:/home/work/app-web/php/var/run/app-web.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param UNIQUE_ID $request_id;
include fastcgi_params;
}
error_log /var/log/nginx/test-error.log debug;
}
Note the internal; directive
Created a virtualhost for symfony application in local system
Here is the nginx config file
server {
listen 80;
server_name local.symfony;
root /home/guest/symfony_demo/web;
rewrite ^/app\.php/?(.*)$ /$1 permanent;
try_files $uri #rewriteapp;
location #rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
# Deny all . files
location ~ /\. {
deny all;
}
location ~ ^/(app|app_dev)\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_index app.php;
send_timeout 1800;
fastcgi_read_timeout 1800;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
# Statics
location /(bundles|media) {
access_log off;
expires 30d;
try_files $uri #rewriteapp;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
On load of app in browser its throwing an error
502 Bad Gateway Error:No input file specified.
Error caught from error.log file:
FastCGI sent in stderr: "Unable to open primary script: /home/guest/symfony_demo/web/app.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: local.symfony, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "local.symfony"
Can anyone help me to configure symfony app to app_dev config file.
Any thoughts??
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
This line is the problem. If you remove it, your error disappears. You may then have Opcache problems due to Symfony using symlinks to the current project.
With $realpath_root$fastcgi_script_name, the web server looks at the "real" path for the PHP script based on the root definition in your server block. Nginx must have read permissions to the path for this to work. Your code is in /home/guest/, if nginx is running as "www-data" give it permissions to your directories, or run nginx as the "guest" user (ignoring the security implications of this).
Why don't you start with configuration from official documentation (http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html#nginx) and when that works, you can try to add your custom configuration (caching of sttaic files ...) ?
This should work:
server {
listen 80;
server_name local.symfony;
root /home/guest/symfony_demo/web;
location / {
try_files $uri /app_dev.php$is_args$args;
}
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
This error happens when nginx is not able to find the php-fpm.sock file.
Can you make sure that the php-fpm.sock file is in the path as mentioned. I had to update fastcgi_pass like below
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
as my php-fpm.sock was there
server {
listen 80;
server_name myapp.local
root /home/jack/Documents/projects/php/myapp/web;
location / {
#try_files $uri $uri/ /app_dev.php?$query_string;
#try_files $uri /app_dev.php$is_args$args;
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /app_dev.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
access_log /var/log/nginx/myapp-access.log;
error_log /var/log/nginx/myapp-error.log;
}
I've been trying to make this work but I couldn't and when I go to myapp.local I got No input file specified.. In the logs I have:
[error] 6867#0: *1 FastCGI sent in stderr: "Unable to open primary script: /usr/share/nginx/html/app.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: myapp.local, request: "GET /app.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "myapp.local"
UPDATE
It looks like it's trying to access /usr/share/nginx/html/app.php, why in the world is it doing that?
nginx -v : 1.4.6
Believe it or not guys, after 4 hours of debugging I realized that it was all about a poor missing semicolon after server_name statement. What a shame!
I have created a default CakePHP 2.4 project and created the Nginx configuration as follows but I am getting these errors from Nginx error log. What I have done wrong?
My environment:
Debian (wheezy)
nginx/1.2.1
project directory /var/www/backhaus
The error is:
$ 2014/06/14 09:39:22 [error] 5952#0: *1 rewrite or internal redirection cycle while processing "/backhaus", client: xxx.x.x.xx, server: azazel, request: "GET /backhaus HTTP/1.1", host: "azazel"
Here is my config from ../sites-available/default:
location /backhaus {
root /var/www/backhaus/app/webroot/;
index index.php;
rewrite ^/* /backhaus;
location ~ ^/(.+\.php)$ {
try_files $uri $uri/ =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Your error is this:
$ 2014/06/14 09:39:22 [error] 5952#0: *1 rewrite or internal
redirection cycle while processing "/backhaus", client: xxx.x.x.xx,
server: azazel, request: "GET /backhaus HTTP/1.1", host: "azazel"
And the error clearly states:
…redirection cycle while processing "/backhaus"…
So now, let’s look at your posted Nginx config:
location /backhaus {
root /var/www/backhaus/app/webroot/;
index index.php;
rewrite ^/* /backhaus;
location ~ ^/(.+\.php)$ {
try_files $uri $uri/ =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
It seems like the issue is your location is /backhaus but then you are redirecting any traffic going to /backhaus to /backhaus via this line:
rewrite ^/* /backhaus;
So I would recommend just removing that rewrite line.