【问题标题】:Nginx and Unicorn Basic ConfigNginx 和 Unicorn 基本配置
【发布时间】:2013-08-09 22:11:11
【问题描述】:

我刚得到一个安装了 nginx、unicorn 和一个新的 rails 应用程序的 VM。我查看了 nginx 配置文件,但我不明白它是如何连接到 unicorn 的,尤其是因为似乎没有任何上游设置(这是大多数教程所说的你需要的)。

这是我的配置设置:

/home/unicorn/unicorn.conf

listen "127.0.0.1:8080"
worker_processes 2
user "rails"
working_directory "/home/rails"
pid "/home/unicorn/pids/unicorn.pid"
stderr_path "/home/unicorn/log/unicorn.log"
stdout_path "/home/unicorn/log/unicorn.log"

/etc/nginx/sites-enabled/default - 只有站点启用目录中的默认文件

server {
        listen   80;
        root /home/rails/public;
        server_name _;
        index index.htm index.html;

        location / {
                try_files $uri/index.html $uri.html $uri @app;
        }

        location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mp3|flv|mpeg|avi)$ {
                        try_files $uri @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_server;
    }

}

服务器似乎正在定义一个位置@app,并将请求传递给http://app_server ...我不确定它从哪里获得app_server ...那会是其他地方定义的上游吗?

有关更多信息,这篇文章的设置与我的 vps 完全相同。 https://www.digitalocean.com/community/articles/how-to-1-click-install-ruby-on-rails-on-ubuntu-12-10-with-digitalocean

【问题讨论】:

    标签: ruby-on-rails nginx unicorn


    【解决方案1】:

    通常app_server 将在另一个文件中定义为上游。例如 - 在我的 debian 系统上,我设置了一个与您类似的位置,指向名为 www 的上游。

    在我的/etc/nginx/sites-enabled 目录中,我有一个名为upstream_www_app 的文件,其内容如下

    upstream www {
      server localhost:24910 fail_timeout=0 weight=5;
    }
    

    24910 是在我的应用程序config/unicorn.rb 中定义的端口,而我的主要nginx.conf 包括sites-enabled 目录中的所有文件。

    【讨论】:

    • 是的,我以为上游会在某个地方定义,但我不知道在哪里。这篇文章与我的设置完全相同,也许它在那里的某个地方我错过了它? digitalocean.com/community/articles/…
    • 我刚刚发现上游在nginx.conf里面。我没有看到它,因为我正在查看启用站点的目录下!
    猜你喜欢
    • 2012-08-17
    • 1970-01-01
    • 1970-01-01
    • 2012-08-04
    • 2021-02-04
    • 2016-07-15
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    相关资源
    最近更新 更多