配置Nginx时一定要小心(1)——目录拼写问题。

1.No input file specified .

非常经典的问题。
哪怕是我这样装过两三次的非新手,也撞在这问题上。

和 404 not found 类似,这个错误的提示是 no input file specified 404 。

最后成功的配置文件,如下。


#user  nobody;
worker_processes  auto;
worker_rlimit_nofile 100000;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  2048;
    multi_accept on;
}

# 新增
# fastcgi.impersonate = 1
# cgi.fix_pathinfo=1
# cgi.force_redirect = 0


http {
    #include       ../virtual_host/*.conf;
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        # server_name  192.168.1.107 ;
        server_name localhost;
        # root "F:\Php_Projects\3K_Project\www.contestia.com\public";
        # root "F:/Php_Projects/3K_Project/www.contestia.com/public";
        # root "F:\Php_Projects\TODO_Laravel\new_version\public";
        root "F:/Php_Projects/TODO_Laravel/new_version/public";
        # root "F:/nginx_www";
        # root "F:\nginx_www";

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        index  index.php index.html index.htm;

        location / {
               # try_files $uri $uri/ /index.php;
               # try_files $uri $uri/ /index.php?$query_string;

               # Laravel路由专用 ↓ ↓ ↓
               try_files $uri $uri/ /index.php?$query_string;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            # root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
        #location \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}



问题日志,揭露了一切问题:

F:/nginx-1.2.1/logs/error.log    line:727


2017/10/27 10:01:35 [crit] 8148#1360: *2 
 GetFileAttributesEx() 
 "F:ginx_www/index.php" failed 
 (123: The filename, directory name, or volume label syntax is incorrect),
 client: 127.0.0.1,
 server: localhost, 
 request: "GET /pic.jpg HTTP/1.1", 
 host: "localhost"
F:/nginx-1.2.1/logs/error.log    line:431


2017/10/26 23:56:43 [crit] 6936#3704: *1 
GetFileAttributesEx()  
"F:\Php_Projects\TODO_Laravelew_version\public/favicon.ico"  failed  
(123: The filename, directory name, or volume label syntax is incorrect),  
client: 127.0.0.1,  
server: localhost,  
request: "GET /favicon.ico HTTP/1.1",  
host: "127.0.0.1",  
referrer: "http://127.0.0.1/"

路途中走的弯路,这里就不说了。

总而言之,Bug产生的关键原因,在于:

1.我是从Windows的文件夹窗口的地址栏,复制地址,粘贴进 Nginx配置文件的 root 路径的。
2.Windows的文件夹分隔符,是 反斜杠 \。Nginx在解析的时候,把 \n 解析成了换行。结果 反斜杠 \字母 n 都丢失了。
3.我这里有三个例子,第1个,因为没有字母 n ,得以幸免。第二个例子,和第三个例子,路径都被 反斜杠 \n开头的文件夹,都转义掉了,所以产生了根本无法访问的路径。
4.所以,404 无法访问,就出现了。




网络上有很多篇说这个问题的垃圾攻略,但没有一篇能解决问题的。但取其精华,我学到了其它的知识

Nginx —— 指出常见nginx.conf文件配置的不规范之处
.user.ini 有关——Nginx报 No input file specified. 的问题解决之路


经验和反思

所以,一定要养成

1.查看日志的好习惯————>日志已经救了你两次了。第一次是逐行排查Nginx的PHP-FPM解析。第二次就是这里。
2.Fiddler监控网络请求,有时候有一点点帮助。
3.Windows的路径全部默认显示反斜杠,这是非常反人性,和非常容易出Bug的一点。切记切记!

塞翁失马,焉知非福。
这里也要感谢,这个 路径反斜杠转义 的错误,没有出现在我写第一个PHP接口时,连环出现。使得我能够躲过一劫,不至于陷入一层坑套一层坑的深坑中。
感谢!这也是我运气好的一方面!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值