This is my error.log from nginx:
2014/10/02 14:51:29 [error] 15936#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 134.106.87.55, server: sumomo.shitteru2.net, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "sumomo.shitteru2.net"
this is my enabled site:
server {
listen 80;
server_name sumomo.shitteru2.net;
index index.php index.html index.htm;
location / {
root /mnt/firstsite;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
As far as I can see everything is very simple so it should work. I even copied it directly from http://wiki.nginx.org/PHPFcgiExample#Connecting_nginx_to_PHP_FPM. Do you guys see any potential problems?
I made a solution I can use everywhere in /etc/nginx/snippets/common.conf:
index index.php index.html index.htm index.nginx-debian.html;
location ~ \.php$
{
include snippets/fastcgi-php.conf;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
And now all my site config files look very simple:
server {
listen 80;
listen [::]:80;
server_name do-it-big.com www.do-it-big.com;
root /var/www/doitbig;
client_max_body_size 10m;
include snippets/common.conf;
location / {
try_files $uri $uri/ /index.php?$args;
}
}
Related
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
I am trying to use PHP in my machine. I have nginx server running few other servers along.
Due to curiosity on how to use PHP , i tried to install php-cli and php5-fpm.
The nginx file below seems to work , however on front-end i get the error " 404". When i checked the error log , i found the error
"2016/03/29 14:28:50 [error] 19752#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: ::1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "localhost:84"
So i am assuming either my php5-fpm configuration is wrong or my nginx config is wrong .
Here is my nginx configuration file:
server {
listen 84 default_server;
listen [::]:84 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
server_name localhost;
location / {
index index.php index.html index.htm;
root /home/sijan/personal/php_site;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_index index.php;
#include fastcgi_params;
}
}
I followed the following link from Digital Oceans and skip few steps to install MySQL since i will be using psql.
Any Help will be Highly appreciated.
I can't immediately see anything wrong with your nginx config but I've found that PHP-FPM and Nginx can be really really temperamental when configuring... Try the following Nginx config instead...
server {
listen 84 default_server;
listen [::]:84 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name _;
location / {
index index.php index.html index.htm;
root /home/sijan/personal/php_site;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_connect_timeout 10;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 512k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 512k;
fastcgi_temp_file_write_size 512k;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_keep_conn on;
include fastcgi_params;
}
}
Also, don't forget that you've got your Nginx server listening on port 84 in your config, not the standard port 80.
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!
Calling "http://test.local/" in the browser returns a "403 Forbidden" error.
Calling "http://test.local/index.php" works well.
If I create a "index.html" file, calling "http://test.local/" shows me the "index.html" file correctly.
So just the "index.php" file doesn't work.
This is my vhost configuration:
server {
listen 80;
server_name test.local;
root /var/www/public;
index index.html index.htm index.php;
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;
}
}
The error.log file contains this error:
2013/12/28 14:00:57 [error] 2854#0: *50 directory index of "/var/www/public/" is forbidden, client: 10.0.2.2, server: test.local, request: "GET / HTTP/1.1", host: "test.local"
Why's that? I've googled a lot now and checked permissions (which are all set to 777) and tried lots of other stuff too, but I don't get it working.
I'm new to nginx so probably I'm just missing something.
Thanks a lot!
Your configuration seems fine, but I think it can be simplified, try this
server {
listen 80;
server_name test.local;
root /var/www/public;
index index.php;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
im trying to get the zabbix-frontend to work with nginx.
this here is my nginx conf:
server {
listen 80;
server_name localhost;
root /var/www/test/htdocs;
index index.php index.html index.htm;
location /zabbix {
alias /usr/share/zabbix;
index index.php;
error_page 403 404 502 503 504 /zabbix/index.php;
location ~ \.php$ {
if (!-f $request_filename) { return 404; }
expires epoch;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~ \.(jpg|jpeg|gif|png|ico)$ {
access_log off;
expires 33d;
}
}
location / {
try_files $uri $uri/ /index.php;
include /etc/nginx/proxy_params;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_read_timeout 120;
include /etc/nginx/fastcgi_params;
}
include /etc/nginx/security;
include /etc/nginx/main_rules;
}
the php scripts in /zabbix are working! but files like /usr/share/zabbix/css.css are NOT being served (404). in the error log is this:
2013/07/19 20:23:33 [error] 13583#0: *1 open() "/var/www/test/htdocs/zabbix/css.css" failed (2: No such file or directory), client: xxx, server: localhost, request: "GET /zabbix/css.css HTTP/1.1"
so as we can see, nginx is looking for the file in the main root directory /var/www/test/htdocs/ instead of in the alias directory /usr/share/zabbix/.
why is that so and how can i fix that?
I would try to separate them locations. /zabbix with alias only and ~ ^/zabbix/*.php$ with fastcgi. Both outside the / location with root.