我环顾了其他示例,并尝试复制一个非常基本的nginx服务器布局。但是,它根本不起作用(除了 example.com,它正确地重定向到 index.html)。
这是我的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;
}
我能够使用以下设置修复我的nginx配置。我最终只是使用 node.js 的代理系统,将所有流量重定向到端口 15301,即 node.js 正在侦听的端口。
http {
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /var/www/royhowie.com/public_html/;
index index.html;
# Make site accessible from http://localhost/
server_name localhost;
location / {
proxy_pass http://localhost:15301/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
}
}