nginx配置文件无法正常工作

时间:2014-02-19 15:28:35

标签: javascript html nginx

我环顾了其他示例,并试图复制一个非常基本的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;
}

1 个答案:

答案 0 :(得分:0)

我能够通过以下设置修复我的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;
        }
    }
}
相关问题