如何配置 nginx 以指示“/”到我的主页
how to configure nginx to indicate ’/‘ to my main page
我有一个 Django 项目,我的 Web 静态文件位于 '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
如何正确配置?
通过将位置/中的'root'改为'/path/to/the/index/directory'
而不是django项目的根目录,问题已经解决,这样在html文件中一般仍然可以使用静态资源的相对路径。
我有一个 Django 项目,我的 Web 静态文件位于 '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
如何正确配置?
通过将位置/中的'root'改为'/path/to/the/index/directory'
而不是django项目的根目录,问题已经解决,这样在html文件中一般仍然可以使用静态资源的相对路径。