关于nginx配置的问题

目录结构如下:
root
└── data
   └── domain.com
      ├── admin
      └── index

文件夹admin是网站后台网页目录
文件夹index是网站前台目录

nginx 部分配置如下:

location / {
    root /data/domain.com/index;
    index index.html index.htm;
}

location /admin/{
    root /data/domain.com/admin;
    index index.php index.html index.htm;
}

访问 http://domain.com 正常,但是访问http://domain.com/admin/ 提示 404

请问各位大神我想访问 http://domain.com nginx转发到 index目录下,访问http://domain.com/admin/nginx转发到 admin目录下如何设置?

阅读 3.5k
3 个回答

这样配置会在domain.com/admin 下面找admin的

root/index 的配置一般都会放在 server下面的,不要放在location中

一般这样配置好了

server {
    root /data/domain.com;
    index index.php index.html index.htm;

    location /{
        try_files $uri $uri/ /index.php?s=$uri&$args;
    }
    ……

}

location /放最下面试试。

location /admin/ {
    root /data/domain.com;
    index index.php index.html index.htm;
}

第二个 location 中的 root 多了 admin

有问题先看日志。这种错误,看下 nginx 的日志就清楚了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题