2015-03-19 40 views
0

昨天我能夠看到默認頁面,如您看到here。今天無法使用Nginx + Unicorn訪問rails應用程序

但我修改nginx的訪問在麒麟上運行我的Rails應用程序配置,並開始獲得404

/etc/nginx/nginx.conf

user www-data; 
worker_processes 4; 
pid /var/run/nginx.pid; 

events { 
    worker_connections 768; 
    # multi_accept on; 
} 

http { 
    ## 
    # Basic Settings 
    ## 

    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 

    include /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    ## 
    # Logging Settings 
    ## 

    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log; 

    ## 
    # Gzip Settings 
    ## 

    gzip on; 
    gzip_disable "msie6"; 

    ## 
    # Virtual Host Configs 
    ## 

    include /etc/nginx/conf.d/*.conf; 
    include /etc/nginx/sites-enabled/*; 
} 

的/ etc/nginx的/網站可用/默認

upstream unicorn { 
    server unix:/tmp/unicorn.integrity_matters.sock fail_timeout=0; 
} 

server { 
    listen 80; 
    server_name localhost; 
    root /home/ubuntu/integrity_matters/current/public; 

    location ~ ^/assets/ { 
    gzip_static on; 
    expires max; 
    add_header Cache-Control public; 
    } 

    try_files $uri/index.html $uri @unicorn; 
    location @unicorn { 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 
    proxy_pass http://unicorn; 
    } 

    error_page 500 502 503 504 /500.html; 
    client_max_body_size 20M; 
    keepalive_timeout 10; 
} 

MY_APP_ROOT /配置/ unicorn.rb

root = "/home/imdeploy/integrity_matters/current" 
working_directory root 
pid "#{root}/tmp/pids/unicorn.pid" 
stderr_path "#{root}/log/unicorn.log" 
stdout_path "#{root}/log/unicorn.log" 

listen "/tmp/unicorn.integrity_matters.sock" 
worker_processes 2 
timeout 30 

# Force the bundler gemfile environment variable to 
# reference the capistrano "current" symlink 
before_exec do |_| 
    ENV\["BUNDLE_GEMFILE"\] = File.join(root, 'Gemfile') 
end][2] 

我還證實連接到EC2安全組允許22,80和443的端口。請爲EC2找到attached安全規則。

我重新啓動了nginx和獨角獸多次,並驗證nginx和獨角獸正常運行。

我也驗證了nginx訪問和錯誤日​​志,但是看不到任何活動。

請幫幫忙,

回答

0

最後我可以修復它。問題在於AWS期望讓nginx SSL感知。

所以爲了使它工作,我創建了自簽名證書並修改了nginx配置。以下是最終配置。

的/ etc/nginx的/網站可用/默認

upstream integrity_matters_server { 
    server unix:/tmp/unicorn.integrity_matters.sock fail_timeout=0; 
} 

server { 
    listen 80; 
    server_name ec2-52-10-245-227.us-west-2.compute.amazonaws.com; 
    rewrite ^/(.*) https://ec2-52-10-245-227.us-west-2.compute.amazonaws.com permanent; 
} 

server { 
    listen 443; 
    server_name ec2-52-10-245-227.us-west-2.compute.amazonaws.com; 
    root /home/ubuntu/integrity_matters/current/public; 

    ssl on; 
    ssl_certificate  /etc/nginx/ssl/nginx_im.crt; 
    ssl_certificate_key /etc/nginx/ssl/nginx_im.key; 
    ssl_protocols  SSLv3 TLSv1; 
    ssl_prefer_server_ciphers on; 

    location ~ ^/assets/ { 
    gzip_static on; 
    expires max; 
    add_header Cache-Control public; 
    } 

    try_files $uri @integrity_matters; 
    location @integrity_matters { 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header X-Forwarded-Proto https; 
    proxy_set_header Host $host; 
    proxy_redirect off; 
    proxy_pass http://integrity_matters_server; 
    } 

    error_page 500 502 503 504 /500.html; 
    client_max_body_size 20M; 
    keepalive_timeout 10; 
} 

post而我們在進行SSL配置也非常有用。

0

nginx.conf包括配置文件路徑爲/etc/nginx/sites-enabled/*;/etc/nginx/sites-available/default默認的配置文件。

sites-enabled更改爲sites-available,然後重試。

+0

它已經符號鏈接。 – 2015-03-19 08:03:18

相關問題