使用nginx web服务器和php.nginx正在工作,我看到'欢迎来到nginx!' 但在尝试访问php页面时,我得到"访问被拒绝".我还安装了php-fastcgi.
这是我的nginx默认conf:
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
Run Code Online (Sandbox Code Playgroud)
我活化状态security.limit_extensions = .php .php3 .php4 .php5 .html,并listen = /var/run/php5-fpm.sock在/etc/php-fpm.d/www.conf和cgi.fix_pathinfo = 0在/etc/php5/fpm/php.ini
我重启了nginx和php5-fpm.
谢谢你的帮助.
如果您有次要位置,请这样做
location / {
try_files $uri $uri/ =404;
root /path/to/your/www;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Run Code Online (Sandbox Code Playgroud)
这两个参数是魔术酱:
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Run Code Online (Sandbox Code Playgroud)
如果您尝试使用 NGINX 将 HTML 解析为 PHP 并且收到错误Access denied,则需要更改 PHP 配置设置。
在 Ubuntu 16 上,您需要更新的文件位于/etc/php/7.0/fpm/pool.d/www.conf.
转到它所说的行;security.limit_extensions = .php .php3 .php4 .php5 .php7
将其替换为此security.limit_extensions = .php .html。请注意,前导分号已被删除。
然后重新启动 PHP sudo systemctl restart php7.0-fpm。该问题应该得到解决。
有关更多信息,请参阅此更详细的指南:修复使用 Nginx 将 HTML 解析为 PHP 时的“访问被拒绝”错误
| 归档时间: |
|
| 查看次数: |
33078 次 |
| 最近记录: |