簡體   English   中英

用於Puma的Nginx代理:忽略我的配置,不從套接字提供服務

[英]Nginx proxy for Puma: Ignoring my config, not serving from socket

我正在嘗試閱讀以下文章: https : //www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-puma-and-nginx-on-ubuntu-14-04

與新的Amazon Linux EC2實例。 我正在使用現成的/etc/nginx/nginx.conf文件,並將配置文件添加到/ etc / nginx / sites-default / default

彪馬似乎運轉良好:

/home/ec2-user/flviewer/shared/log/puma_error.log:[8006] *在Unix:///home/ec2user/flviewer/shared/sockets/tmp/puma.sock上收聽

但這顯示在/var/log/nginx/error.log中:

2016/12/12 05:33:00 [錯誤] 11018#0:* 1 open()“ / usr / share / nginx / html / flviewer”失敗(2:無此類文件或目錄),客戶端:173.73.119.219 ,服務器:本地主機,請求:“ GET / flviewer HTTP / 1.1”,主機:“ 54.86.222.53”

當它應該查看我打開的套接字時,為什么要在“ / usr / share / nginx / html / flviewer”中查找呢?

這是我的配置,如“ nginx -T”轉儲的:

# configuration file /etc/nginx/sites-available/default:
upstream app {
  # Path to Puma SOCK file, as defined previously
  server unix:/home/ec2-user/flviewer/shared/tmp/sockets/puma.sock fail_timeout=0;
}

server {
  listen 80;
  server_name localhost;

  root /home/ec2-user/flviewer/current/public;

  try_files $uri/index.html $uri @app;

  location @app {
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_redirect off;
    #proxy_http_version 1.1;
    proxy_set_header Connection '';
    proxy_pass http://app;
    #autoindex on;
  }

   location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
   }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

沒事。 我將/etc/nginx.conf剝離為此,並啟動並運行。 我不得不扔掉了nginx.conf中所有的樣板。 這有效:

配置文件:

# Run nginx as a normal console program, not as a daemon
daemon off;
user ec2-user;

# Log errors to stdout
error_log /dev/stdout info;

events {} # Boilerplate

http {

  # Print the access log to stdout
  access_log /dev/stdout;

  # Tell nginx that there's an external server called @app living at our socket
  upstream app {
    server unix:/home/ec2-user/flv/shared/tmp/sockets/puma.sock fail_timeout=0;
  }

  server {

    # Accept connections on localhost:2048
    listen 80;
    server_name localhost;

    # Application root
    root /home/ec2-user/flv/shared/public;

    # If a path doesn't exist on disk, forward the request to @app
    try_files $uri/index.html $uri @app;

    # Set some configuration options on requests forwarded to @app
    location @app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://app;
    }

   location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;

  }
}

我認為這與使用默認的nginx配置文件有關。 嘗試將/etc/nginx/sites-available/default移至/etc/nginx/sites-enabled/flviewer

$ mv /etc/nginx/sites-available/default /etc/nginx/sites-enabled/flviewer

然后重新加載並重新啟動nginx。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM