我需要有一些由 subdir 组织的应用程序,这里是我将用于它们的 url:
http://172.17.0.158/beanstalk
http://172.17.0.158/phpmyadmin
http://172.17.0.158/laravel
我需要它是 IP 或任何主机名,所以我将 server_name 设置为:
server_name "";
我需要它是“类似文件夹”的应用程序,但这些应用程序安装在不同的根目录中。
其中两个工作正常:
http://172.17.0.158/beanstalk
http://172.17.0.158/phpmyadmin
一,我不能工作:
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。我无法使 root 或别名工作。经过数小时的尝试和猜测 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;
}
这让 Nginx 很满意,因为 phpmyadmin 是 /usr/share 中的一个文件夹。因此,无需进行任何调整即可使其正常工作。
文件 /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;
}
}
有人对这一切有什么要说的吗?