Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Dokku Nginx提供静态文件_Node.js_Nginx_Dokku - Fatal编程技术网

Node.js Dokku Nginx提供静态文件

Node.js Dokku Nginx提供静态文件,node.js,nginx,dokku,Node.js,Nginx,Dokku,我正在尝试为dokku上的node.js webapp设置部署。但是,我的应用程序的根路径只需要提供静态html、css和javascript,所有其他路由“/api/…”应发送到我的节点应用程序,该应用程序正在端口5000上运行。我已尝试使用以下nginx.ssl.conf.template进行设置: http { proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive

我正在尝试为dokku上的node.js webapp设置部署。但是,我的应用程序的根路径只需要提供静态html、css和javascript,所有其他路由“/api/…”应发送到我的节点应用程序,该应用程序正在端口5000上运行。我已尝试使用以下nginx.ssl.conf.template进行设置:

http {
    proxy_cache_path  /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
    proxy_temp_path /var/tmp;
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    gzip on;
    gzip_comp_level 6;
    gzip_vary on;
    gzip_min_length  1000;
    gzip_proxied any;
    gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_buffers 16 8k;

    upstream ceresshop_api {
      server 127.0.0.1:5000;
      keepalive 64;
}
server {
  listen      [::]:$NGINX_PORT;
  listen      $NGINX_PORT;
  server_name $NOSSL_SERVER_NAME;
  access_log  /var/log/nginx/${APP}-access.log;
  error_log   /var/log/nginx/${APP}-error.log;
  return 301 https://\$host:$NGINX_SSL_PORT\$request_uri;
}

server {
  listen      [::]:$NGINX_SSL_PORT ssl spdy;
  listen      $NGINX_SSL_PORT ssl spdy;
  server_name $SSL_SERVER_NAME;
  access_log  /var/log/nginx/${APP}-access.log;
  error_log   /var/log/nginx/${APP}-error.log;
$SSL_DIRECTIVES

  keepalive_timeout   70;
  add_header          Alternate-Protocol  $NGINX_SSL_PORT:npn-spdy/2;
  location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) {
         root /data/public;
         access_log off;
         expires max;
       }
  location    / {

    gzip on;
    gzip_min_length  1100;
    gzip_buffers  4 32k;
    gzip_types    text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml  application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml;
    gzip_vary on;
    gzip_comp_level  6;

    proxy_pass  http://$APP;
    proxy_http_version 1.1;
    proxy_set_header Upgrade \$http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host \$http_host;
    proxy_set_header X-Forwarded-Proto \$scheme;
    proxy_set_header X-Forwarded-For \$remote_addr;
    proxy_set_header X-Forwarded-Port \$server_port;
    proxy_set_header X-Request-Start \$msec;
  }
  include $DOKKU_ROOT/$APP/nginx.conf.d/*.conf;
}
但是,我不确定将的“root”参数指向何处

location ~ ^/(images/|img/|javascripts/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico|index.html) {
         root /data/public;
         access_log off;
         expires max;
       }

因为应用程序是用dokku部署的。在上下文中,我尝试使用ngix静态服务的文件位于我的应用程序目录的“public”director中。

nginx配置位于容器外部,因此无法访问容器内部的静态文件


如果需要,可以将这些文件移动到容器中已装入的卷,然后将nginx指向该已装入的卷。否则,您的应用程序将需要以节点应用程序通常的方式为它们提供服务。我想看看heroku的nodejs buildpack规定了什么是最佳选项。

我尝试使用dokku的docker options功能在我的应用程序目录中装载公用文件夹,以便docker选项等同于:
部署选项:-v/home/dokku/public:/app/public运行选项:-v/home/dokku/public:/app/public
在部署项目后删除/home/dokku/public文件夹时,该目录为空。使用docker选项时,该目录中已有的文件不会从该目录复制到主机上。在部署过程中,您需要以某种方式处理将文件复制到该目录的问题