Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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;
#   }
#}
share|improve this question
    
You might want to try using php5-fpm instead of fastcgi. FPM still uses the fastcgi stuff, so your config shouldn't change, but I've found it works more easily and is less finicky than fastcgi. –  Shauna Jan 19 '13 at 23:25
    
Thanks, I will look into it –  dan Jan 19 '13 at 23:55
    
No luck, same result. –  dan Jan 20 '13 at 0:23
add comment

2 Answers

up vote 2 down vote accepted

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;
}
share|improve this answer
    
tried it, same result –  dan Jan 20 '13 at 0:57
    
192.168.x.x - - [19/Jan/2013:19:20:42 -0500] "GET /index.php HTTP/1.1" 404 56 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) is the result given in the access.log. There is no entry in the error.log for the recent inquiry. –  dan Jan 20 '13 at 1:19
    
@dan - What URL are you trying to go to? –  Shauna Jan 20 '13 at 1:46
    
the ip address of the server on my lan. 192.168.2.x/index.php –  dan Jan 20 '13 at 1:58
    
Do you have an "index.php" file? According to your question, you're using "test.php". –  Shauna Jan 20 '13 at 2:24
show 2 more comments

I figured it out. I changed the fastcgi_pass 127.0.0.1:9000 to fastcgi_pass localhost:9000. I also changed commented out the root in the php{} block. I have root declared in the http{} block. For the fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; was added.

The php.inc may have helped. I dont know enough about it to say either way.

Thanks Shauna!!!!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.