1. 程式人生 > >LNMP環境問題--nginx不解析php檔案

LNMP環境問題--nginx不解析php檔案

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。