CentOS 7 下配置nginx服务器根目录

在上篇文章中(点击打开链接)我们安装了LNMP环境,但是在安装完成之后我发现Nginx的根目录在/usr/share/nginx/html/  下面,一般都是放在/var/www/html/ 目录下面。所以我们来修改一下根目录所在地。

打开nginx配置文件,nginx.conf。里面的include的意思是,加载制定目录下面的所有以.conf结尾的配置

我把我的配置放在了 /etc/nginx/conf.d/*.conf; 下面

所以我们找到指定目录进行编辑。

#vim /etc/nginx/conf.d/default.conf
 
server{
    listen 80; #监听80端口
    server_name test.com; #访问的网址 例如:baidu.com   qq.com
    root /var/www/html; #制定根目录 例如:/var/www/html/baidu /var/www/html/qq
    sendfile on;
    #文件上传大小限制
    client_max_body_size    1000m;
 
    location / {
        index index.php index.html index.htm;
        if (-e $request_filename) {
            break;
        }
        if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php/$1 last;
            break;
        }
    }
    
    location ~ \.php {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PHP_VALUE "open_basedir=$document_root:/tmp/:/var/www/html";#这里是你的项目地址
        fastcgi_param HTTP_PROXY "";
        include fastcgi_params;
    }
    
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

//重启nginx

service nginx restart

403 Forbidden 解决办法

当访问时候,nginx 会按照 index.php  index.html  index.htm 的先后顺序在根目录中查找文件。如果这三个文件都不存在,那么nginx就会返回403 Forbidden。所以你可以吧你的/usr/share/nginx/html/目录下面的文件移动到/var/www/html/  即可,或者建立一个index.php index.html。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值