Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 4220  / 2 Years ago, wed, january 26, 2022, 8:36:31

I have nginx successfully running on my home server. I dont have a .com specified because it is just a trial run until I get everything figured out. I can navigate to the server ip address and the index.html is served fine. I try to navigate to the test.php and it tells me "No input file specified"



Here is me nginx.conf:



user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##

server { # php/fastcgi
listen 80;
server_name localhost;
root /var/www;
location = /favicon.ico {
empty_gif;
# return 204;
}

location ~ .php$ {
root /var/www;
fastcgi_pass 127.0.0.1:9000;
}
}

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##

#include /etc/nginx/naxsi_core.rules;

##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##

#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;

##
# Virtual Host Configs
##

upstream php5 {
server unix:/tmp/php-fastcgi.sock;
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
# include /var/www/*;
}


#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}

More From » nginx

 Answers
4

What I generally do is have a "php.inc" file that I just include with my virtual hosts. It has all the settings necessary to tell Nginx what to do with PHP files (complete with URL rewriting for things like Wordpress).



index index.php;

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}

location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}


Just drop that into /etc/nginx (you'll need to do it via command line with sudo). Then, edit your config to add include php.inc; (it automatically knows where to look) in your server{} block. Reload (sudo service nginx reload) or restart (sudo service nginx restart) Nginx, and your PHP file should work.



Edit: Here are a couple of other things I've noticed in your config, and what I do differently.



One of the things that I do differently is to leave the main nginx.conf file alone, and instead, declare virtual hosts in either /etc/nginx/sites-available (with a symlink to sites-enabled) or /etc/nginx/conf.d. I've found this avoids issues all around, but then, I generally have to manage several virtual host domains at any given time, and set up with this in mind from the get-go.



Another thing I noticed in your config is that you have a root /var/www; block inside the location ~ .php$ {} block. You shouldn't need to do this (and, according to this article I found, may be causing your issue), as location blocks within a server block will inherit as needed.



Combining these three tactics (leave vhost configuration out of nginx.conf and instead put it in conf.d, use an include file for PHP stuff, and allow location blocks to inherit as needed) should result in a clean configuration setup without much hassle.



So, your nginx.conf file should look like this (or the default, if you have it backed up):



user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##

#include /etc/nginx/naxsi_core.rules;

##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##

#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}


#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}


Then, add an entry in /etc/nginx/conf.d/default.conf like this:



server {
listen 80;
server_name localhost;
root /var/www;
include php.inc;
}

[#33124] Thursday, January 27, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pipeag

Total Points: 489
Total Questions: 107
Total Answers: 115

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;