【发布时间】:2019-08-04 06:50:09
【问题描述】:
我正在尝试使用 nginx 来提供给我的静态网站。它的文件夹结构是这样的:
static_website/
index.html
www.example.com/
resources.example.com/
uploads.example.com/
根目录中的index.html 文件是httrack 生成的文件,它只包含到www.example.com/index.html 的重定向。
在文件夹www.example.com 中是所有html 文件,在另外两个文件夹中是css、javascript 和image 文件。
这里是nginx配置:
server {
index index.php index.html index.htm;
server_name example.com;
location / {
root /var/www/static_website/www.example.com;
try_files $uri $uri/ =404;
index index.html;
}
}
我可以浏览页面,但没有加载 css、javascript 和图像文件。 html中的一个css文件的路径是这样的:
href="../resources.example.com/style.css"
我设法让这个工作的唯一方法是拥有这样的网址:
example.com/www.example.com/
这样,所有路径都是正确的。我想避免这种情况,只需使用 example.com。 有没有办法做到这一点?
【问题讨论】:
-
尝试添加另一个匹配所有资源文件的
location,例如:location ~ \.(css|js|jpg|png|svg)$ { root /var/www/static_website; } -
谢谢,就是这样。如果您将其添加为答案而不是评论,我可以将其标记为已接受
标签: nginx nginx-config