[英]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.