サブディレクトリごとにいくつかのアプリケーションを整理する必要があります。これらに使用する URL は次のとおりです。
http://172.17.0.158/beanstalk
http://172.17.0.158/phpmyadmin
http://172.17.0.158/laravel
IPまたは任意のホスト名である必要があるため、server_nameを次のように設定します。
server_name "";
「フォルダのような」アプリケーションである必要がありますが、それらのアプリケーションは異なるルートにインストールされています。
それらのうちの2つは正常に機能しています:
http://172.17.0.158/beanstalk
http://172.17.0.158/phpmyadmin
そして1つ、私は仕事をすることができません:
http://172.17.0.158/laravel
これらのサーバーブロックは次のとおりです。
server {
listen 172.17.0.158:80;
# Anonymous server (ip or hostname)
server_name ""; ## this is an IP address (or wrong server_name) based server
# Configure log
access_log /var/log/access.log;
error_log /var/log/error.log debug;
# Index files
index index.php index.html index.htm;
# PHP scripts are sent to php5-fpm
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
# We don't need .ht files with nginx.
location ~ /\.ht {
deny all;
}
# Set header expirations on per-project basis
location ~* \.(?:ico|css|js|jpe?g|JPE?G|png|svg|woff|webp)$ {
expires max;
}
include /etc/nginx/locations-enabled/*.conf;
}
ここに私のロケーション ( /etc/nginx/locations-enabled/
) ファイルがあります:
ファイル /etc/nginx/locations-enabled/beanstalkd-console.conf (これは正常に動作しています)
location /beanstalk {
root /var/www/beanstalk_console;
access_log /var/log/nginx/beanstalkd-access.log;
error_log /var/log/nginx/beanstalkd-error.log debug;
index index.php index.html index.htm;
location ~ ^/beanstalk/(.+\.php)$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/beanstalk/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /var/www/beanstalk_console;
}
}
location /beanstalkd {
rewrite ^/* /beanstalk last;
}
location /beanstalk_console {
rewrite ^/* /beanstalk last;
}
Beanstalk ファイルは機能していますが、そのためにはばかげたシンボリック リンクを作成する必要がありました。/var/www/beanstalk_console/beanstalk は /var/www/beanstalk_console/public を指します。ルートもエイリアスも機能させることができませんでした。Nginxが何を望んでいるかを何時間も試して推測した後、あきらめてリンクを作成しました。
ファイル /etc/nginx/locations-enabled/phpmyadmin.conf (これは正常に動作しています)
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
phpmyadmin は /usr/share 内のフォルダーであるため、これは Nginx を喜ばせます。したがって、機能させるための微調整はありません。
ファイル /etc/nginx/locations-enabled/laravel.conf (動作していません)
location /laravel {
alias /var/www/laravel/public;
access_log /var/log/nginx/laravel-access.log;
error_log /var/log/nginx/laravel-error.log debug;
index index.php index.html index.htm;
location ~ ^/laravel/(.+\.php)$ {
alias /var/www/laravel/public;
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/laravel/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
alias /var/www/laravel/public;
}
}
私のために、これを機能させることができませんでした。アクセスしようとすると、次のデバッグ メッセージが生成されます。
2013/10/20 19:45:27 [debug] 27308#0: *1 http cl:-1 max:1048576
2013/10/20 19:45:27 [debug] 27308#0: *1 rewrite phase: 3
2013/10/20 19:45:27 [debug] 27308#0: *1 post rewrite phase: 4
2013/10/20 19:45:27 [debug] 27308#0: *1 generic phase: 5
2013/10/20 19:45:27 [debug] 27308#0: *1 generic phase: 6
2013/10/20 19:45:27 [debug] 27308#0: *1 generic phase: 7
2013/10/20 19:45:27 [debug] 27308#0: *1 access phase: 8
2013/10/20 19:45:27 [debug] 27308#0: *1 access phase: 9
2013/10/20 19:45:27 [debug] 27308#0: *1 access phase: 10
2013/10/20 19:45:27 [debug] 27308#0: *1 post access phase: 11
2013/10/20 19:45:27 [debug] 27308#0: *1 try files phase: 12
2013/10/20 19:45:27 [debug] 27308#0: *1 content phase: 13
2013/10/20 19:45:27 [debug] 27308#0: *1 content phase: 14
2013/10/20 19:45:27 [debug] 27308#0: *1 open index "/var/www/laravel/public/index.php"
2013/10/20 19:45:27 [debug] 27308#0: *1 internal redirect: "/laravel/index.php?"
2013/10/20 19:45:27 [debug] 27308#0: *1 http cl:-1 max:1048576
2013/10/20 19:45:27 [debug] 27308#0: *1 rewrite phase: 3
2013/10/20 19:45:27 [debug] 27308#0: *1 post rewrite phase: 4
2013/10/20 19:45:27 [debug] 27308#0: *1 generic phase: 5
2013/10/20 19:45:27 [debug] 27308#0: *1 generic phase: 6
2013/10/20 19:45:27 [debug] 27308#0: *1 generic phase: 7
2013/10/20 19:45:27 [debug] 27308#0: *1 access phase: 8
2013/10/20 19:45:27 [debug] 27308#0: *1 access phase: 9
2013/10/20 19:45:27 [debug] 27308#0: *1 access phase: 10
2013/10/20 19:45:27 [debug] 27308#0: *1 post access phase: 11
2013/10/20 19:45:27 [debug] 27308#0: *1 try files phase: 12
2013/10/20 19:45:27 [debug] 27308#0: *1 http script copy: "/var/www/laravel/public"
2013/10/20 19:45:27 [debug] 27308#0: *1 http script var: "/laravel/index.php"
2013/10/20 19:45:27 [debug] 27308#0: *1 trying to use file: "/laravel/index.php" "/var/www/laravel/public/laravel/index.php"
2013/10/20 19:45:27 [debug] 27308#0: *1 trying to use file: "=404" "/var/www/laravel/public=404"
2013/10/20 19:45:27 [debug] 27308#0: *1 http finalize request: 404, "/laravel/index.php?" a:1, c:2
2013/10/20 19:45:27 [debug] 27308#0: *1 http special response: 404, "/laravel/index.php?"
2013/10/20 19:45:27 [debug] 27308#0: *1 http set discard body
2013/10/20 19:45:27 [debug] 27308#0: *1 xslt filter header
2013/10/20 19:45:27 [debug] 27308#0: *1 HTTP/1.1 404 Not Found
Server: nginx/1.2.6 (Ubuntu)
Date: Sun, 20 Oct 2013 21:45:27 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Content-Encoding: gzip
2013/10/20 19:45:27 [debug] 27308#0: *1 write new buf t:1 f:0 000000000156F898, pos 000000000156F898, size: 194 file: 0, size: 0
2013/10/20 19:45:27 [debug] 27308#0: *1 http write filter: l:0 f:0 s:194
2013/10/20 19:45:27 [debug] 27308#0: *1 http output filter "/laravel/index.php?"
2013/10/20 19:45:27 [debug] 27308#0: *1 http copy filter: "/laravel/index.php?"
2013/10/20 19:45:27 [debug] 27308#0: *1 image filter
2013/10/20 19:45:27 [debug] 27308#0: *1 xslt filter body
2013/10/20 19:45:27 [debug] 27308#0: *1 http postpone filter "/laravel/index.php?" 000000000156FAC8
2013/10/20 19:45:27 [debug] 27308#0: *1 http gzip filter
2013/10/20 19:45:27 [debug] 27308#0: *1 malloc: 0000000001564D50:16384
2013/10/20 19:45:27 [debug] 27308#0: *1 gzip alloc: n:1 s:5936 a:8192 p:0000000001564D50
2013/10/20 19:45:27 [debug] 27308#0: *1 gzip alloc: n:1024 s:2 a:2048 p:0000000001566D50
2013/10/20 19:45:27 [debug] 27308#0: *1 gzip alloc: n:1024 s:2 a:2048 p:0000000001567550
2013/10/20 19:45:27 [debug] 27308#0: *1 gzip alloc: n:1024 s:2 a:2048 p:0000000001567D50
2013/10/20 19:45:27 [debug] 27308#0: *1 gzip alloc: n:512 s:4 a:2048 p:0000000001568550
2013/10/20 19:45:27 [debug] 27308#0: *1 gzip in: 000000000156FB08
2013/10/20 19:45:27 [debug] 27308#0: *1 gzip in_buf:000000000156F970 ni:00000000006BE7C0 ai:116
2013/10/20 19:45:27 [debug] 27308#0: *1 posix_memalign: 0000000001568D60:4096 @16
2013/10/20 19:45:27 [debug] 27308#0: *1 malloc: 00000000015AF180:4096
2013/10/20 19:45:27 [debug] 27308#0: *1 deflate in: ni:00000000006BE7C0 no:00000000015AF180 ai:116 ao:4096 fl:0 redo:0
2013/10/20 19:45:27 [debug] 27308#0: *1 deflate out: ni:00000000006BE834 no:00000000015AF180 ai:0 ao:4096 rc:0
2013/10/20 19:45:27 [debug] 27308#0: *1 gzip in_buf:000000000156F970 pos:00000000006BE7C0
2013/10/20 19:45:27 [debug] 27308#0: *1 gzip in: 000000000156FB18
2013/10/20 19:45:27 [debug] 27308#0: *1 gzip in_buf:000000000156F9C0 ni:00000000006BE120 ai:61
2013/10/20 19:45:27 [debug] 27308#0: *1 deflate in: ni:00000000006BE120 no:00000000015AF180 ai:61 ao:4096 fl:0 redo:0
2013/10/20 19:45:27 [debug] 27308#0: *1 deflate out: ni:00000000006BE15D no:00000000015AF180 ai:0 ao:4096 rc:0
2013/10/20 19:45:27 [debug] 27308#0: *1 gzip in_buf:000000000156F9C0 pos:00000000006BE120
2013/10/20 19:45:27 [debug] 27308#0: *1 gzip in: 000000000156FB28
2013/10/20 19:45:27 [debug] 27308#0: *1 gzip in_buf:000000000156FA10 ni:00000000006BE1A0 ai:402
2013/10/20 19:45:27 [debug] 27308#0: *1 deflate in: ni:00000000006BE1A0 no:00000000015AF180 ai:402 ao:4096 fl:4 redo:0
2013/10/20 19:45:27 [debug] 27308#0: *1 deflate out: ni:00000000006BE332 no:00000000015AF234 ai:0 ao:3916 rc:1
2013/10/20 19:45:27 [debug] 27308#0: *1 gzip in_buf:000000000156FA10 pos:00000000006BE1A0
2013/10/20 19:45:27 [debug] 27308#0: *1 free: 0000000001564D50
2013/10/20 19:45:27 [debug] 27308#0: *1 http chunk: 10
2013/10/20 19:45:27 [debug] 27308#0: *1 http chunk: 188
2013/10/20 19:45:27 [debug] 27308#0: *1 write old buf t:1 f:0 000000000156F898, pos 000000000156F898, size: 194 file: 0, size: 0
2013/10/20 19:45:27 [debug] 27308#0: *1 write new buf t:1 f:0 0000000001568ED0, pos 0000000001568ED0, size: 4 file: 0, size: 0
2013/10/20 19:45:27 [debug] 27308#0: *1 write new buf t:0 f:0 0000000000000000, pos 00000000006C25C8, size: 10 file: 0, size: 0
2013/10/20 19:45:27 [debug] 27308#0: *1 write new buf t:1 f:0 00000000015AF180, pos 00000000015AF180, size: 188 file: 0, size: 0
2013/10/20 19:45:27 [debug] 27308#0: *1 write new buf t:0 f:0 0000000000000000, pos 000000000049DAD8, size: 7 file: 0, size: 0
2013/10/20 19:45:27 [debug] 27308#0: *1 http write filter: l:1 f:1 s:403
2013/10/20 19:45:27 [debug] 27308#0: *1 http write filter limit 0
2013/10/20 19:45:27 [debug] 27308#0: *1 writev: 403
2013/10/20 19:45:27 [debug] 27308#0: *1 http write filter 0000000000000000
2013/10/20 19:45:27 [debug] 27308#0: *1 http copy filter: 0 "/laravel/index.php?"
2013/10/20 19:45:27 [debug] 27308#0: *1 http finalize request: 0, "/laravel/index.php?" a:1, c:2
2013/10/20 19:45:27 [debug] 27308#0: *1 http request count:2 blk:0
2013/10/20 19:45:27 [debug] 27308#0: *1 http finalize request: -4, "/laravel/index.php?" a:1, c:1
2013/10/20 19:45:27 [debug] 27308#0: *1 set http keepalive handler
2013/10/20 19:45:27 [debug] 27308#0: *1 http close request
2013/10/20 19:45:27 [debug] 27308#0: *1 http log handler
2013/10/20 19:45:27 [debug] 27308#0: *1 free: 00000000015AF180
2013/10/20 19:45:27 [debug] 27308#0: *1 free: 0000000000000000
2013/10/20 19:45:27 [debug] 27308#0: *1 free: 000000000156EB40, unused: 8
2013/10/20 19:45:27 [debug] 27308#0: *1 free: 0000000001568D60, unused: 3315
2013/10/20 19:45:27 [debug] 27308#0: *1 event timer add: 3: 65000:1382305592455
2013/10/20 19:45:27 [debug] 27308#0: *1 free: 000000000156E210
2013/10/20 19:45:27 [debug] 27308#0: *1 free: 000000000156E730
2013/10/20 19:45:27 [debug] 27308#0: *1 hc free: 0000000000000000 0
2013/10/20 19:45:27 [debug] 27308#0: *1 hc busy: 0000000000000000 0
2013/10/20 19:45:27 [debug] 27308#0: *1 tcp_nodelay
2013/10/20 19:45:27 [debug] 27308#0: *1 reusable connection: 1
2013/10/20 19:45:27 [debug] 27308#0: *1 post event 00007F0777F20148
==> /var/log/nginx/laravel-access.log <==
172.17.0.100 - - [20/Oct/2013:19:45:27 -0200] "GET /laravel/ HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36"
==> /var/log/nginx/laravel-error.log <==
2013/10/20 19:45:27 [debug] 27308#0: *1 delete posted event 00007F0777F20148
2013/10/20 19:45:27 [debug] 27308#0: *1 http keepalive handler
2013/10/20 19:45:27 [debug] 27308#0: *1 malloc: 000000000156E210:1024
2013/10/20 19:45:27 [debug] 27308#0: *1 recv: fd:3 -1 of 1024
2013/10/20 19:45:27 [debug] 27308#0: *1 recv() not ready (11: Resource temporarily unavailable)
2013/10/20 19:45:27 [debug] 27308#0: *1 free: 000000000156E210
私が理解できなかったのは、正しい index.php ファイルを取得する理由です。
open index "/var/www/laravel/public/index.php"
そして、私に
*1 HTTP/1.1 404 Not Found
これが最後のバージョンです。これは別のものです:
location ~ ^{{ laravel_site_base_url }}(/?(.*))$ {
root {{ webserver_document_root }}{{ laravel_site_base_url }}/public;
# URLs to attempt, including pretty ones.
try_files $uri /index.php?$2 /index.php;
access_log /var/log/nginx{{ laravel_site_base_url }}-access.log;
error_log /var/log/nginx{{ laravel_site_base_url }}-error.log debug;
location ~ ^{{ laravel_site_base_url }}/(.+\.php)$ {
root {{ webserver_document_root }}{{ laravel_site_base_url }}/public;
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include {{ nginx_config_directory }}/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
rewrite ^/(.*)/$ /$1 permanent;
}
これにより、次のデバッグ ログが生成されます。
2013/10/20 19:49:12 [debug] 27842#0: *1 http cl:-1 max:1048576
2013/10/20 19:49:12 [debug] 27842#0: *1 rewrite phase: 3
2013/10/20 19:49:12 [debug] 27842#0: *1 http script regex: "^/(.*)/$"
2013/10/20 19:49:12 [notice] 27842#0: *1 "^/(.*)/$" does not match "/laravel", client: 172.17.0.100, server: , request: "GET /laravel HTTP/1.1", host: "172.17.0.158"
2013/10/20 19:49:12 [debug] 27842#0: *1 post rewrite phase: 4
2013/10/20 19:49:12 [debug] 27842#0: *1 generic phase: 5
2013/10/20 19:49:12 [debug] 27842#0: *1 generic phase: 6
2013/10/20 19:49:12 [debug] 27842#0: *1 generic phase: 7
2013/10/20 19:49:12 [debug] 27842#0: *1 access phase: 8
2013/10/20 19:49:12 [debug] 27842#0: *1 access phase: 9
2013/10/20 19:49:12 [debug] 27842#0: *1 access phase: 10
2013/10/20 19:49:12 [debug] 27842#0: *1 post access phase: 11
2013/10/20 19:49:12 [debug] 27842#0: *1 try files phase: 12
2013/10/20 19:49:12 [debug] 27842#0: *1 http script var: "/laravel"
2013/10/20 19:49:12 [debug] 27842#0: *1 trying to use file: "/laravel" "/var/www/laravel/public/laravel"
2013/10/20 19:49:12 [debug] 27842#0: *1 http script copy: "/index.php?"
2013/10/20 19:49:12 [debug] 27842#0: *1 http script capture: ""
2013/10/20 19:49:12 [debug] 27842#0: *1 trying to use file: "/index.php?" "/var/www/laravel/public/index.php?"
2013/10/20 19:49:12 [debug] 27842#0: *1 trying to use file: "/index.php" "/var/www/laravel/public/index.php"
2013/10/20 19:49:12 [debug] 27842#0: *1 internal redirect: "/index.php?"
そして、私が見るブラウザで
No input file specified.
#nginx の人々は、これは PHP の問題だと言っていました。私はそれを購入しません。なぜなら、それはこのサーバー ブロックに基づいていたからです。変更を開始する前は、それは非常にうまく機能していました。
ファイル: /etc/nginx/sites-enabled/laravel (変更前は動作していました)
server {
listen 172.17.0.158:80;
server_name ""; ## this is an IP address (or wrong server_name) based server
location ~ ^/laravel(/?(.*))$ {
# URLs to attempt, including pretty ones.
try_files $uri /index.php?$2;
root /var/www/laravel/public/;
access_log /var/log/nginx/laravel-access.log;
error_log /var/log/nginx/laravel-error.log error;
}
rewrite ^/(.*)/$ /$1 permanent;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# We don't need .ht files with nginx.
location ~ /\.ht {
deny all;
}
# Set header expirations on per-project basis
location ~* \.(?:ico|css|js|jpe?g|JPE?G|png|svg|woff|webp)$ {
expires max;
}
}
このすべてについて何か言いたいことはありますか?