別のフォルダーからファイルをロードするようにnginxを構成するためのヘルプが必要です。これが私の設定です:
index index.php;
server {
server_name domain.com;
root /www/domain.com/www/;
location / {
try_files $uri $uri/ /php_www/index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /php_www/index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
error_page 404 /404.html;
error_log /var/log/nginx/error.log;
}
問題は、/php_www/がnginxで定義されたルート内に配置されていないことです。
これを行うために必要な4つの異なるフォルダーがあります。フォルダー構造は次のようになります。
/www/domain.com/www/
/www/domain.com/php_www/
/www/domain.com/content1/
/www/domain.com/content2/
私がやろうとしているのは、訪問者がdomain.com/page1/content1/
アクセスしたときに、たとえばcontent1フォルダーからコンテンツをロードしたいということです。この理由は、個別のリポジトリを持ついくつかのgitプロジェクトがあるためです...これにより、他に何も影響を与えることなく、Webサイトの特定の領域を本番環境にプッシュできます。/ wwwフォルダ内のすべてのファイル/コンテンツにもアクセスできないようにしたいので、コンテンツを探してURLをブルートフォース攻撃することはできません。
うまくいけば、これは理にかなっています!
実用的な解決策(このコメントから抜粋)
location ^~ / {
root /www/domain.com/php_www/;
try_files $uri $uri/ /index.php;
location ~* \.(?:php|html)$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
include /etc/nginx/fastcgi_params;
}
}