Apacheを実行すると、PHPアプリケーションの静的ファイルは正常に処理されますが、Nginxを実行するとアクセスが拒否されます。 )をユーザーとして使用します。Apacheが提供する静的ファイルで、Nginxでは使用しません
したがって、問題はNginxまたはphp-fpmの設定にあります。ここで
はnginx.conf
コンテンツの一部である:ここで
user stephane;
worker_processes 1;
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
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;
upstream php5-fpm-sock {
server unix:/home/stephane/programs/install/php5-fpm.sock;
}
server {
listen 80;
server_name localhost;
charset utf-8;
location/{
root html;
index index.html index.htm;
}
location ~ \.php$ {
try_files $uri = 404;
fastcgi_index index.php;
fastcgi_pass php5-fpm-sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
}
include conf.d/*.conf;
include sites-enabled/*;
}
はnginxのバーチャルホストの設定です:
server {
listen 443;
server_name dev.extrapack.group.com;
root /home/stephane/dev/php/projects/Extrapack-Mon/public;
ssl on;
ssl_certificate /home/stephane/programs/install/nginx/conf/sites-available/extrapack.group.com.crt;
ssl_certificate_key /home/stephane/programs/install/nginx/conf/sites-available/extrapack.group.com.key;
location /simplesaml {
index index.php;
alias /usr/share/simplesaml/www;
location ~ ^/simplesaml/(module\.php)(/.+)$ {
include fastcgi_params;
fastcgi_pass php5-fpm-sock;
fastcgi_split_path_info ^/simplesaml/(module\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME /usr/share/simplesaml/www/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass php5-fpm-sock;
}
}
location/{
include fastcgi_params;
fastcgi_pass php5-fpm-sock;
fastcgi_split_path_info ^(.+\.php)(.*)$;
try_files $uri /index.php?$args;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS 'on'; # Make PHP-FPM aware that this vhost is HTTPs enabled
fastcgi_param APPLICATION_ENV development;
fastcgi_index index.php;
}
}
そして(すべての静的リソースへのアクセス正常に動作します)Apacheのバーチャルホストの設定:
<VirtualHost *:443>
ServerName dev.extrapack.group.com
DocumentRoot "/home/stephane/dev/php/projects/Extrapack-Mon/public"
<Directory "/home/stephane/dev/php/projects/Extrapack-Mon/public">
Options Indexes FollowSymLinks Includes
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
設定で変更したいことがいくつかあります。とりわけ 'location/{'ブロックです。ここでは、 'try_files'指示文があるので、' fastcgi_pass'指示文を使用しないでください。見つからない場合は、PHPブロックに渡します。 'try_files $ uri $ uri//index.php$args;' 2番目の '$ uri /'は、マスカレードするディレクトリを再帰するよう指示します。したがって、資産がサブフォルダにある場合、NGINXはそれを見つけることができます。これを省略すると、 'root 'でファイルを検索し、サブフォルダは検索しません。 –
'try_files $ uri /index.php?$ args;'を 'location /'ブロックの 'try_files $ uri $ uri /index.php$args; 'に置き換え、Nginxサーバを再起動しました。静的ファイルへのアクセスは拒否されました。 'fastcgi_pass php5-fpm-sock;を削除すると、phpファイルが解析不能になり、ダウンロードのために提供されました。 – Stephane