牛骨文教育服务平台(让学习变的简单)
博文笔记

LNMP环境问题--nginx不解析php文件

创建时间:2017-05-23 投稿人: 浏览次数:372

php、nginx都装完了,配置了好长时间都不对。刚整好。

nginx.conf 开始是

server {     
        listen       8080;
        server_name  localhost;
        #charset koi8-r;
        access_log  logs/host.access.log  main;
        root    /Users/yangshuo/work/index.php;
        location / {
            root   html;
            index  index.html index.htm index.php;
        }

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

        location ~ .*.(eot|otf|ttf|woff)$ {
            root html;
            add_header Access-Control-Allow-Origin *;
        }

        # 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$ {
            root           html;
            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;
        }
        }

后来改成

server {
        listen       8080;
        server_name  localhost;
        root    /Users/yangshuo/work/index.php;
        index index.php index.html;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

        #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$ {
            root           /Users/yangshuo/work/index.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;
        #}
    }

重启再访问就可以了。


加index。

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。