nginx

时间:2017-01-19 09:47:53

标签: nginx containers

我有一个nginx容器,用作Web应用程序的前端。

这是我的配置文件:

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    root   /usr/share/nginx/html/shaka-player-master/demo;
    index  index.html index.htm;


    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}


    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

如果我指向localhost:port,它会正确地返回我/usr/share/nginx/html/shaka-player-master/demo/index.html ...但我有一个问题:

这个应用程序,一个破折号库,需要我运行一个python脚本,生成文件名" deps.js",base.js和其他,托管在:

/usr/share/nginx/html/shaka-player-master/third_party/closure/goog/base.js 
/usr/share/nginx/html/shaka-player-master/dist/deps.js 
/usr/share/nginx/html/shaka-player-master/shaka-player.uncompiled.js 

这些文件位于这些文件夹中,但浏览器会返回404,因为我不知道如何从配置文件中公开这些内容。

我尝试添加一些代码,如:

location = third_party/closure/goog/base.js {

root /usr/share/nginx/html/shaka-player-master/third_party/closure/goog/base.js;
}

但仍然是404。

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

正确的locationroot语法为:

location = /third_party/closure/goog/base.js {
    root /usr/share/nginx/html/shaka-player-master;
}
location = /dist/deps.js {
    root /usr/share/nginx/html/shaka-player-master;
}
location = /shaka-player.uncompiled.js {
    root /usr/share/nginx/html/shaka-player-master;
}

有关详细信息,请参阅locationroot手册页。

还有一些配置允许此root作为默认值,并使演示位置成为例外。

但是,还有另一个潜在问题 - 为什么您的应用程序使用localhost:9900作为服务器名称?