[英]nginx config file not working
我查看了其他示例,并尝试复制一个非常基本的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/
。 我drawsomething.html
,以便当有人去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配置。 通过将所有流量重定向到端口15301(node.js监听的端口),我最终只使用了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;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.