0
我环顾了其他例子,试图复制一个非常基本的nginx服务器布局。但是,它根本没有工作(除了example.com,它可以正确地重定向到index.html)。nginx配置文件不工作
这是我的nginx的配置文件:
server {
listen 80;
root /var/www/example.com/public_html;
server_name example.com;
location/{
root /var/www/example.com/public_html/templates;
try_files $uri $uri/ /index.html;
}
location /draw/ {
root /var/www/example.com/public_html/templates/projects/draw;
try_files $uri $uri/ /drawsomething.html;
}
location ~ \.(gif|jpg|png)$ {
root /var/www/example.com/public_html/templates/pic;
}
}
基本上,我存储所有/templates/
。我想这样做,当有人去example.com/draw
它显示drawsomething.html
,这是在/var/www/example.com/public_html/templates/projects/draw
。我遵循网站上的例子,它似乎没有工作。尽管如此,图像的重定向似乎正在起作用。另外,如果我想包含脚本文件呢?我可以使用:
location ~ \.js$ {
root /var/www/example.com/public_html/templates/script;
}
@ AD7six所以我只是把一个主根放在顶部,然后把每个位置块的子根? – royhowie
其实我在那里犯了一个错误 - 有一个服务器根,所以它不会中断 - 它看起来有点奇怪:你知道什么根源在做什么?有urls/foo'/foo.gif','/ foo.js'去不同的地方可能会变得很混乱。 – AD7six
@ AD7six基本上,现在我想'/ template'下的所有东西。像“index.html”这样的主文件将位于此目录中。在模板内部,我会有'/ pic','/ projects'和'/ script'(稍后移动脚本)。因此,'example.com/draw'应该得到'templates/projects/draw /'里面的draw.html。脚本/图像文件将大致相同,除了在各自的目录中。 – royhowie