2016-09-05 6 views
1

だから、OSXでnginxとphpを取得しようとしています。私は、このガイドの後: https://www.sylvaindurand.org/setting-up-a-nginx-web-server-on-os-x/OSXでPHPを読み込むためにnginxを取得できない

をしかし、私のホームフォルダ内のサイトを指すようにルートを設定し、そこに2つの単純なファイルを置く:

index.htmを

<body> 
    <h1>Here I am!</h1> 
    <p>NGINX is working.</p> 
</body> 

index.php

<html> 
<head> 
    <title>PHP Test</title> 
</head> 
<body> 
<?php echo '<p>PHP is working!</p>'; ?> 
</body> 
</html> 

私はブラウザを直接htmlファイルに向けるか、最初に読み込むためにnginx.confを設定してうまく動作します。しかし、私は任意のPHPファイルをロードすることはできません、今すぐそれは "ファイルが見つかりません"と言う。私は周りを見回し、同様の問題を抱えた人々を見つけましたが、私が見つけたソリューションのどれも私の問題を解決しませんでした。私はPHPの初心者ですので、私は暗闇の中で少し動揺しています。私が間違っていたことは何ですか?

user Maddux staff; 
worker_processes 1; 

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

#pid  logs/nginx.pid; 


events { 
    worker_connections 1024; 
} 


http { 
    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 localhost; 

     #charset koi8-r; 

     #access_log logs/host.access.log main; 

     location/{ 
      root /Users/Maddux/Sites/; 
      index index.php index.html index.htm; 
    } 

     #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/Maddux/Sites/; 
      fastcgi_pass 127.0.0.1:9000; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME /scripts$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; 
    # } 
    #} 
    include servers/*; 
} 

答えて

0

あなたlocation ~ \.php$ブロックは、あなたのセットrootとして混乱して、彼らはすぐにそれをオーバーライドします。

は、ここに私のnginx.confです。

あなたのPHPスクリプトを見つけるためにnginxと同じドキュメントルートを使用するには、PHP-FPMをしたい場合は、SCRIPT_FILENAMEの値がいずれかに設定する必要があります。

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 

か:

fastcgi_param SCRIPT_FILENAME $request_filename; 

あなたのケースでは、両方の値が同じです。

また、rootが継承されているので、の値をすべてlocationブロックに入れる必要はありません。単一のrootディレクティブをserverブロックの上部に配置し、値が異なるlocationブロック内にのみrootディレクティブを配置するのが普通です。詳細については、this documentを参照してください。

+0

ありがとうございました。私はあなたの提案された修正を行いましたが、私はまだ "File not found"を得ています。しかし、これは少なくとも私に多くの調査を提供します。私はここで学ぶことがたくさんある。 – Maddux

関連する問題