【发布时间】:2015-04-13 22:50:02
【问题描述】:
我一直在尝试在我的 nginx 网络服务器上配置多个 webapp,但我无法运行一个需要将 $document_root 设置为 laravel 公共文件夹的 Laravel 应用程序。 我目前正在尝试使用别名指令对其进行配置,但由于不明原因,这不起作用。这就是我想要做的。
# Default server configuration
#
server {
listen 80;
# SSL configuration
#
listen 443 ssl;
error_log /var/log/nginx/error.log warn;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
set $root_path '/var/www/html';
root $root_path;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name localhost;
location /paperwork {
alias /var/www/html/paperwork/frontend/public;
try_files $uri $uri/;
#location ~ \.php {
# fastcgi_split_path_info ^(.+\.php)(.*)$;
# fastcgi_pass unix:/var/run/php5-fpm.sock;
# include /etc/nginx/fastcgi_params;
# #fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
# #fastcgi_intercept_errors on;
#}
}
#location @paperwork {
# rewrite /paperwork/(.*)$ /paperwork/index.php/$1 last;
#}
location / {
}
location /wallabag {
try_files $uri $uri/ /index.php;
}
location /laverna {
try_files $uri/ /index.php;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#try_files $uri $uri/ =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
}
为了测试我的“别名”配置,我在 /var/www/html/paperwork/frontend/public/test.php 中放置了一个“test.php”文件,并尝试通过https://IP/paperwork/test.php 访问它。我收到 404 错误,而 nginx 错误日志中没有任何内容。 如果我在浏览器中尝试https://IP/paperwork/frontend/public/test.php,它会显示 test.php 文件而没有错误。 如果我在 php 位置取消注释 try_files 行,没有任何变化。
如果我将 test.php 复制到 /var/www/html/paperwork/test2.php 并访问 https://IP/paperwork/test2.php 文件显示没有错误,所以我可以在这里看到别名不起作用,因为没有 test2 .php 在文书工作公共目录中。
如果我取消注释文件位置内的 php 位置,我可以有不同的行为。这样,https://IP/paperwork/test.php 之类的请求不会显示 404,而是显示空白屏幕。
我已经浏览了很多与此相关的论坛/问题,但我无法为显示 test.php 之类的简单任务获得工作配置...
谢谢!
【问题讨论】:
-
感谢您提出如此有用的问题.. 先生,您让我开心