如何正确配置nginx php,php – 如何在nginx中正确配置alias指令?

我一直在尝试在我的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 …

谢谢 !

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值