nginx 配置Nginx.conf文件

修改root根目录配置


注:

什么都不修改的情况下,服务器默认显示的是html目录下的 index.html 首页内容

因为 没修改配置文件之前 是这样的:

但是 在实际项目开发中,很多都不是默认目录,所以就要手动配置修改了

以下只稍微分了两种情况:

A)在html目录下继续新建文件(如:myApp),里面放的就是你的项目代码文件

此时将其中的

            location / {
                  root    html;
                  index   index.php index.html index.htm;
            }
改为

            location / {
                  root    html/myApp;
                  index   index.php index.html index.htm;
            }
然后再将
location ~ \.php$ {
                  root                html;
                  fastcgi_pass    127.0.0.1:9000;
                  fastcgi_index   index.php;
                  fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name;
                  include            fastcgi_params;
            }
改为
location ~ \.php$ {
                  root                html/myApp;
                  fastcgi_pass    127.0.0.1:9000;
                  fastcgi_index   index.php;
                  fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name;
                  include            fastcgi_params;
            }


然后 别忘了重启然后重启nginx 就可以访问到你重新配置的项目首页了!



B)第二种情况,其实原理是一样,改的地方也是一样的。

这种情况,不在html目录下新建文件夹,要访问其他盘下的项目文件也是可以的

比如此时,nginx此时安装在f盘,但是我要把默认首页改到d盘的myApp目录下的首页,其修改配置文件如下:

(其实是一样的和第一种情况,就再啰嗦一点吧)

此时将其中的

            location / {
                  root    html;
                  index   index.php index.html index.htm;
            }
改为

            location / {
                  root    d:/myApp;
                  index   index.php index.html index.htm;
            }
然后再将
location ~ \.php$ {
                  root                html;
                  fastcgi_pass    127.0.0.1:9000;
                  fastcgi_index   index.php;
                  fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name;
                  include            fastcgi_params;
            }
改为
location ~ \.php$ {
                  root                d:/myApp;
                  fastcgi_pass    127.0.0.1:9000;
                  fastcgi_index   index.php;
                  fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name;
                  include            fastcgi_params;
            }

然后,还是重启你的nginx,就可以看到你配置的首页了:



批注:1.10.3及以上版本的nginx location ~ \.php$中的配置是注释掉了,是不需要配置的

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值