简体   繁体   中英

Nginx and Unicorn Basic Config

I just got VM which had nginx, unicorn and a fresh rails app installed. I looked at the nginx config file, and I do not understand how it connects to unicorn, especially since there doesn't seem to be any upstream setting (which is what most tutorial's say you need).

Here are my config settings:

/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 - only default file within sites-enabled directory

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;
    }

}

The server seems to be defining a location @app, and passing requests to http://app_server ... I am not sure where does it obtain the app_server ... would that be an upstream defined elsewhere?

Fore more info, this article has the exact same set up as my vps. https://www.digitalocean.com/community/articles/how-to-1-click-install-ruby-on-rails-on-ubuntu-12-10-with-digitalocean

Normally app_server would be defined in another file as an upstream. For example - on my debian system I have a location set up similar to yours pointing to an upstream called www

in my /etc/nginx/sites-enabled directory I have a file called upstream_www_app with the following content

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

24910 is the port defined in my applications config/unicorn.rb and my main nginx.conf includes all files in the sites-enabled directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM