私は次の設定を試してみようとしています。これを序文するために、私は、単一のIPアドレス、FQDN、および/またはDNSを使用して、単一のPHPベースのWebサイト/アプリケーションを提供するサーバー上で動作するNginx/PHP FastCGIの実装を行っています。今、別のサーバーに関する同じシナリオがあります。違いは、複数のクライアントサイト(1つはWordpressサイト)をサーバーする必要があるということです。私はまた、これまでの想像力のどんなストレッチでも、Nginxの専門家ではない。ロケーションブロックとFastCGIプロキシ
概要: サーバーブロックのドキュメントルートは'/usr/share/nginx/html'
、Nginxの既定値です。 http://xxx.xxx.xxx.76からの問題ではなく、問題なく機能します。今や、クライアントがブラウザアドレスhttp://xxx.xxx.xxx.76/pmhsを例として入力するように要求されています。彼らのPHPベースのサイトが提供され、その他のサイトが設定され提供されるためにはhttp://xxx.xxx.xxx.76/clientのようになります。
これらのクライアントのドキュメントルートディレクトリは、標準のCentOS 7フォルダ'/srv'
にあります。すべてのクライアントは、'/srv/www/{client}.production/public_html'
フォルダにあるサイトコンテンツを持つように設定されています。私が掘り下げてきた設定例のほとんどは、このタイプの設定にはあまり関係ありません。ほとんどの場合、すべてのサーバやDNSがルーティングを少し分かりやすくしています(私の見解では合流点)。
server {
## -------------------------------------------------
# define virtual server configuration
## -------------------------------------------------
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm index.php;
access_log /var/log/nginx/default.access.log main;
error_log /var/log/nginx/default.error.log debug;
rewrite_log on;
## -------------------------------------------------
# default site/ip address
# @ serve nginx welcome page
## -------------------------------------------------
location =/{
try_files $uri $uri/;
}
## -------------------------------------------------
# favicon.ico location filter
## -------------------------------------------------
location = /favicon.ico { access_log off; log_not_found off; }
## -------------------------------------------------
# do not serve hidden files
## -------------------------------------------------
location ~ /\. { access_log off; log_not_found off; deny all; }
## -------------------------------------------------
# client website location block
## -------------------------------------------------
location ~ ^\/(?<client>[\w-_]+) {
# reset the document root for the client
#root /srv/www/$client.production/public_html;
alias /srv/www/$client.production/public_html;
# set the port used for the clients fastcgi pool
if ($client = "belmond") { set $port 9000; }
if ($client = "freeboard") { set $port 9001; }
if ($client = "pmhs") { set $port 9002; }
if ($client = "vesta") { set $port 9003; }
#return 200 $document_root$uri;
# nginx pass to php fastcgi - serve client web
#location ~ [^/]\.php(/|$) {
#}
}
location @fastcgi_proxy {
fastcgi_split_path_info ^(.+?\.php)(.*)$;
set $orig_path $fastcgi_path_info;
try_files $fastcgi_script_name =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $orig_path;
fastcgi_param PATH_TRANSLATED $document_root$orig_path;
set $temp "/var/lib/php/fpm/session";
fastcgi_param TEMP $temp;
fastcgi_read_timeout 500;
fastcgi_ignore_client_abort on;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_buffer_size 8k;
fastcgi_buffers 64 8k;
fastcgi_temp_file_write_size 256k;
}
## -------------------------------------------------
# redirect server error pages
# @ serve nginx static page(s) /50x.html
## -------------------------------------------------
error_page 500 502 503 504 /50x.html;
location = /50x.html {
try_files $uri $uri/;
}
}
私は正規表現を使用してクライアントの場所をキャプチャすることができますが、それは自分自身が、私が起こって見たものに基づいて、次に何をすべきかについてはほとんど「ぼやけ」を取得するために開始します。私がベースのip addyにCURLしたとき、それは期待されるもので、Nginxの「ようこそ」ページが返されます。
クライアント名(戻り値200 $ document_root $ uri;コメントなし)を持つ同じaddyを渡すと、document_urlは正しくエイリアスされていますが、今は瞬時に損失しています。最終的には、すべてのクライアントサイトをphp-fpm fastcgiプロキシにプロキシ設定してサービスを提供したいと思います($ portコードが定義されていますが、まだ使用されていません)。
目標がどうなるか...
をちょうどこのをクリーンアップする方法についてなど、任意の方向を探していると、さらにプロセスでnginxの設定に自分自身を教育しながら、それが正常に動作しますが、メインのIPのために、このですアドレス(は現在、この設定あたりの作業):
URL = xxx.xxx.xxx.76 or xxx.xxx.xxx.76/
[serve] /usr/share/nginx/html/(*.html) content
[from] root /usr/share/nginx/html;
URL = xxx.xxx.xxx.76/pmhs or xxx.xxx.xxx.76/pmhs/
[serve] /srv/www/pmhs.production/public_html/(*.php)
[from] root srv/www/pmhs.production/public_html;
URL = xxx.xxx.xxx.76/acme or xxx.xxx.xxx.76/acme/
[serve] /srv/www/acme.production/public_html/(*.php)
[from ] root srv/www/acme.production/public_html;
(そのサーバーのディレクトリからクライアントのサイトをサーブする方法を決定する必要があります)
これは意味がありますか?私はかなり近いと思うが、それが本当かどうかはわからない。
あなたが書いたこととやったことから、すべてが正しいように見えます。あなたは正しいセットアップを持っている、一般的なアイデアは完全に良い( 'パス'から引っ張ったものに応じて別のfpmポートへのプロキシ)、あなたが残しているのは、nginx設定構文を下ろしてポートの変数はアドレスバーの内容によって異なります。私にはうまく見えます。 – Mjh
cliから $> curl http://xxx.xxx.xxx.76/pmhs サーバーから301の応答が返されますが、アクセスログにはエラーログは書き込まれません。逆に、ブラウザのURLから http://xxx.xxx.xxx.76/pmhs サーバーから403 [Forbidden]返信を受け取りました。アクセスログとエラーログの両方に書き込まれた行を取得します。 * 4ディレクトリインデックス "/srv/www/pmhs.production/public_html"は禁止されています。クライアント:xx.xx.xx.xxx、server:localhost、request: "GET/pmhs/HTTP/1.1 "、host:" xxx.xxx.xxx.76 " 標準のphpinfoページを表示するためのindex.phpファイルがあります。アイデア? – Doktor13
ディレクトリインデックス "/srv/www/pmhs.production/public_html"は禁止されています。ディレクトリのアクセス許可をチェックしましたか? Nginxがそのディレクトリにアクセスできないかのように見えます。 – MMT