如何配置nginx以指示我的主页面的“/”

时间:2017-08-29 14:07:58

标签: django nginx web-deployment

我有一个django项目,我的网络静态文件位于'web/'目录

这是结构:

➜  web git:(ycw.alpha) tree -L 4
.
└── forward
    ├── asserts
    │   ├── img
    │   │   ├── background
    │   │   ├── qr
    │   │   └── thumb
    │   └── style
    │       ├── css
    │       └── sass
    ├── index.html
    ├── package.json
    ├── script.js
    ├── source
    └── unit

我配置了Nginx conf,我希望nginx在我申请自己的网站时'web/forward/index.html'直接指示'http://example.com'

我是这样做的事情:

location / {
     index index.html
     root /path/to/my/django/project/;
}

location /index.html {
     alias /path/to/my/django/project/web/forward/index.html;
}

它确实直接重定向到'index.html',但问题是'index.html'中有一些静态文件(例如img或css)的引用,路径是相对路径,如'./asserts/style/css/index.css'所以因此找不到这些文件为404

我该如何正确配置?

1 个答案:

答案 0 :(得分:0)

问题已通过将位置/ 中的“root”更改为'/path/to/the/index/directory' 而不是django项目的根目录来解决,这样您就可以了仍然可以在html文件中使用静态资源的相对路径。