无法访问Rails应用程序使用的Nginx +独角兽
昨天,我能看到默认页面就像你看到的这里一>
Yesterday I was able to see default page like you see here.
不过今天我修改配置的nginx的访问是在麒麟运行我的Rails应用程序,并开始渐渐404。
But today I modified config for nginx to access my rails application which is running on unicorn and started getting 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。
I also verified that the security groups attached to EC2 allows 22, 80 and 443 ports. Please find attached security rules for EC2.
我重新启动nginx的和麒麟多次证实nginx的和麒麟运行正常。
I restarted nginx and unicorn many times and verified that nginx and unicorn are running properly.
我也验证了nginx的访问和错误日志,但无法看到任何在那里的活动。
I also verified nginx access and error logs but could not see any activity there.
请帮忙,
最后我能解决这个问题。这个问题是AWS的期待,使nginx的SSL的。
Finally I am able to fix it. The issue was AWS was expecting to make nginx SSL aware.
因此,为了使工作我创建自签名证书并修改nginx的配置。下面是最终配置。
So to make it work I created self signed certificate and modify nginx configuration. Below is the final configuration.
的/ 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配置也非常有用。
This post also useful while we were making SSL configuration.