現在、1つのリポジトリから3つのアプリケーションを3つに分割しようとしていますが、URL構造は維持しているため、基本的に同じドメインの下の異なる場所を異なるアプリケーションで配信する必要があります。
私が苦労しているのは、アプリの1つが存在しないURLのフォールバックである必要があるため、最初のアプリが一致せず、2番目のアプリが一致しない場合、3番目がリクエストを処理する必要があるということです
私が持っている構造は次のとおりです。
/ etc / nginx / sites-enabled / main_site、ここでは、server_nameと私が手に入れたログは別として、include /etc/nginx/subsites-enabled/*
3つの構成ファイルがあり、各アプリに1つずつあります。
3つの構成ファイルにはそれぞれ、場所ブロックが含まれています。
正規表現でネガティブな先読みを試みました(基本的に他のアプリが処理するURLをハードコードしようとしています)が失敗しました。
要約すると、
/および/ communityは、/ etc / nginx / subsites-enabled / example.org / home(いくつかのperlスクリプト)によって配信される必要があります
/ newsは/etc/nginx/subsites-enabled/example.org/news(wordpress)によって配信される必要があります
その他はすべて/etc/nginx/subsites-enabled/example.org/app(ケーキアプリ)で配信する必要があります
perlビットは正常に動作します。私が抱えている問題は、アプリがニュースを引き継いでいる(おそらく。静的アセットが機能しないなど)。
私の構成は次のとおりです。
/etc/nginx/sites-enabled/example.org:
server {
listen 80;
server_name example.org;
error_log /var/log/nginx/example.org.log;
include /etc/nginx/subsites-enabled/example.org/*;
}
/etc/nginx/subsites-enabled/example.org/home:
location = / {
rewrite ^.*$ /index.pl last;
}
location ~* /community(.*) {
rewrite ^.*$ /index.pl last;
}
location ~ \.pl {
root /var/www/vhosts/home;
access_log /var/log/nginx/home/access.log;
error_log /var/log/nginx/home/error.log;
include /etc/nginx/fastcgi_params;
fastcgi_index index.pl;
fastcgi_param SCRIPT_FILENAME /var/www/vhosts/home$fastcgi_script_name;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
/ etc / ngins / subsites-enabled / news
location /news {
access_log /var/log/nginx/news/access.log;
error_log /var/log/nginx/news/error.log debug;
error_page 404 = /news/index.php;
root /var/www/vhosts/news;
index index.php;
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location ~ \.php {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/vhosts/news$fastcgi_script_name;
}
}
/ etc / nginx / subsites-enabled / app:
location ~ .* {
access_log /var/log/nginx/app/access.log;
error_log /var/log/nginx/app/error.log;
rewrite_log on;
index index.php;
root /var/www/vhosts/app/app/webroot;
if (-f $request_filename) {
expires 30d;
break;
}
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location ~ \.php {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/vhosts/app/app/webroot$fastcgi_script_name;
}
}
location ^~ /news
。b)アプリのブロックについて、できるはずですlocation /
(これはと同じではありませんが、location = /
まだ一致していないすべてのものと一致する必要があります。c)場合によっては(特に正規表現)、順序が重要です-3ブロックを正しい順序で1つのファイルにまとめます。また、ではなくtry_filesを使用します!-e
。最後にwiki.nginx.org/HttpCoreModule#locationを参照してください。
@
します。404を名前付きの場所にマップするerror_pageをセットアップすることもできます。