I have a static html page that has a php form to send an email, the server is nginx and site loads as expected however when I attempt to send an email via the form I get a 404 error,
in the console; POST http://example.com/form-handler.php 404 (Not Found)
and the nginx error.log;
2014/04/07 14:31:19 [error] 10199#0: *48 open()
"/home/deployer/example/current/404.html" failed (2: No such file or
directory), client: 86.131.120.178, server: example.com, request:
"POST /form-handler.php HTTP/1.1", host: "example.com", referrer:
"http://example.com/"
this is my nginx conf for the site;
server {
listen 80;
root /home/deployer/example/current;
index index.php index.html index.htm;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I don't know why it cant find the form...
Related
Here's my server block:
server {
listen 80;
server_name localhost;
root /www/html;
index index.php;
location = / {
autoindex on;
index index.php;
try_files $uri $uri/ =404;
}
location ~*\.(css|js|gif|jpe?g|png)$ {
root /www/html/shared;
rewrite ^/releases(.*)$ $1 last;
expires 5m;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Right now, doing this will just spit out a "403 Forbidden" error when I attempt to access "localhost/". However, the page works perfectly fine if I access it directly-- "localhost/index.php". I can't for the life of me figure out why. The error.log doesn't give me any helpful info nor an error code either--only that the page is "forbidden".
Here's the thrown error:
2017/03/29 14:37:35 [error] 11980#8840: *94 directory index of "C:/www/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
This is a windows-based nginx server.
the answer was kind of disappointing to discover, but i'm gonna answer it so if anyone encounters this goofy issue they can fix it.
php was lookng for files with the prefix "/www/html", NOT "/www/html/", as a result when it wanted my index it was trying to load "/www/htmlindex.php" instead of "/www/html/index.php".
you can fix this by doing either
fastcgi_index /index.php;
or adding a / to the end of your root.
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 installed nginx (with --fpm) on Mac OS X through homebrew, but I can't make it serve php files (html files are OK). Here is the error:
[error] 46118#0: *1 kevent() reported that connect() failed (61:
Connection refused) while connecting to upstream, client: 127.0.0.1,
server: localhost, request: "GET / HTTP/1.1", upstream:
"fastcgi://127.0.0.1:9000", host: "localhost"
below is my site conf file.
server {
listen 80;
root /Users/me/Sites/test/public/;
index index.html index.php;
server_name localhost;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
error_log /var/log/nginx/error.log;
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /Users/me/Sites/test/public/scripts$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
}
}
I'm not very well versed in the fpm setup. What am I doing wrong? Any help would be appreciated, thanx.
Environment:
Mac OS X 10.10.2
nginx:1.6.2
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;
}
}
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.