我正在使用nginx和php7设置服务器
这是我的配置:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/home;
index index.php index.html index.htm;
server_name localhost;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php\$ {
try_files \$uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)\$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
}
但这会继续下载index.php,当我输入IP时它会重定向到index.php - IP / index.php
更新:
将位置location ~ \.php\$ {
更改为location ~ \.php$ {
停止下载文件。
但是现在我收到了错误:
29861#29861: *1 FastCGI sent in stderr: "Unable to open primary script: \/var/www/home\/index.php (No such file or directory)" while reading response header from upstream, client: ..., server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "..."