【发布时间】:2017-12-10 04:14:26
【问题描述】:
按照以下链接enter link description here 中概述的使用 Unicorn 和 nginx 在 digitalocean 中部署 Rails 应用程序的所有步骤之后 ,在浏览器中输入我的 IP 地址会导致我进入默认的 nginx 登录页面,上面写着:“这是在 Fedora 上与 nginx 一起分发的默认 index.html 页面。它位于 /usr/share/nginx/html。
您现在应该将您的内容放在您选择的位置,并在 nginx 配置文件 /etc/nginx/nginx.conf 中编辑根配置指令。
这是我的 etc/nginx/ngingx.conf:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
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;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen [::]:80 default_server;
server_name localhost;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
这里是 /etc/nginx/conf.d/default.conf :
upstream app {
# Path to Unicorn SOCK file, as defined previously
server unix:/tmp/unicorn.myapp.sock fail_timeout=0;
}
server {
listen 80;
server_name localhost;
# Application root, as defined previously
root /root/my_app/public;
try_files $uri/index.html $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;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
还有 config/unicorn.rb
#application root path
app_root = "/var/www/mav"
# Set the working application directory
# working_directory "/path/to/your/app"
working_directory app_root
# Unicorn PID file location
# pid "/path/to/pids/unicorn.pid"
pid "#{app_root}/tmp/pids/unicorn.pid"
# Path to logs
# stderr_path "/path/to/log/unicorn.log"
# stdout_path "/path/to/log/unicorn.log"
stderr_path "#{app_root}/log/unicorn.log"
stdout_path "#{app_root}/log/unicorn.log"
# Number of processes
# worker_processes 4
worker_processes 2
# Time-out
timeout 30
访问独角兽日志时:
tail -20 /var/log/nginx/error.log
2017/12/10 05:06:30 [warn] 8810#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:06:30 [warn] 8818#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:08:31 [error] 8826#0: *2 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 190.104.119.69, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "138.197.195.201", referrer: "http://138.197.195.201/"
2017/12/10 05:29:51 [warn] 19171#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:29:51 [warn] 19176#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:43:49 [warn] 12191#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:43:50 [warn] 12203#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 06:01:29 [warn] 11819#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 06:01:30 [warn] 11825#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 06:01:48 [error] 11833#0: *1 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:01:50 [error] 11833#0: *1 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:01:52 [error] 11833#0: *1 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:04:57 [error] 11833#0: *4 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:04:58 [error] 11833#0: *4 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:04:59 [error] 11833#0: *4 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:04:59 [error] 11833#0: *4 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:11:38 [emerg] 30474#0: unknown directive "And" in /etc/nginx/nginx.conf:91
2017/12/10 06:12:10 [emerg] 31474#0: unknown directive "And" in /etc/nginx/nginx.conf:91
2017/12/10 06:19:31 [emerg] 12641#0: unexpected end of file, expecting "}" in /etc/nginx/nginx.conf:89
2017/12/10 06:43:30 [emerg] 24459#0: unexpected end of file, expecting "}" in /etc/nginx/nginx.conf:89
【问题讨论】:
-
部署后是否重启了Nginx服务?
-
是的,我已经重启了
-
尝试用完整路径或您的应用替换
/root/my_app/public; -
确实。我开始怀疑 \etc/nginx/ngingx.conf 根目录应该是 /usr/share/nginx/html 还是 /var/www/my_app
-
@jungleMan 你明白了。在下面查看我的答案,然后您就可以澄清自己了。
标签: ruby-on-rails nginx deployment unicorn