Nginx 403 错误解决方法技术
前一阵子在配置 Nginx 时,总是出现 403 错误,虽然之后看起来这个问题是非常简单的,但是对于不熟悉的人来讲,能找到问题还是很不容易的,请求了运维大哥,大哥依然找了很久就没能解决问题,最后解决问题了也是碰巧,还是没能真正的理解到 Nginx 的配置的含义。
Nginx 的配置比 Apache 要简单,好像并不能继承默认的 localhost,比如 index 的配置,不愧是轻量级的服务器。大概的配置如下所示:
server {
listen 80;
server_name home.may;
#ssl_certificate ssl/example.com.crt;
#ssl_certificate_key ssl/example.com.key;
error_log /var/log/nginx/home.may.error.log;
charset utf-8;
root /home/leiminglin/work/code/may/lml;
index index.html index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
}
}
在主配置文件 nginx.conf 的最外层中包含配置文件目录 sites_enable(作为 sites_available 的链接目录),如下示例:
include sites_enable/*.conf;
要解决 403 错误,需要保证每个 server 的配置都必须有 index 的配置(这点很重要,我一开始以为会默认继承主配置文件的 index 项),root 的配置,并且每个 root 所指向的路径都必须递归的拥有读写权限。然后按照上面的配置文件来进行修改,基本没有问题的。
相关文章
暂无