我属于完全的小白,去年学习了 rails 相关的知识,最后把项目放在的 heroku 上。最近想到自己以前买的有个搬瓦工 VPS,想着能不能部署到上面,在网上搜索了相关的信息发现可以,自己的所有操作基于以下文章:
部署了几次,一直不能正常访问。刚开始是按照社区上的方法一直用的 Ubuntu16.04,后面在 passenger 文档上按照 Ubuntu18.04。 所用工具如下:
/etc/nginx/nginx.conf
内容如下:
user deploy;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
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;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
/etc/nginx/sites-enabled/default
文件已删除
/etc/nginx/sites-enabled/myapp.conf
内容如下
server {
listen 80;
server_name 23.105.196.112;
# Tell Nginx and Passenger where your app's 'public' directory is
root /var/www/myapp/code/public;
# Turn on Passenger
passenger_enabled on;
passenger_ruby /usr/bin/ruby2.5;
}
以下为/var/log/nginx/access.log
的内容:
[11/Mar/2019:07:34:40 -0400] "GET / HTTP/1.1" 301 0 "-" "curl/7.58.0"
以下为/var/log/nginx/error.log
的内容:
[ N 2019-03-11 07:33:39.7092 18730/T1 age/Wat/WatchdogMain.cpp:1366 ]: Starting Passenger watchdog...
[ N 2019-03-11 07:33:39.7484 18733/T1 age/Cor/CoreMain.cpp:1339 ]: Starting Passenger core...
[ N 2019-03-11 07:33:39.7486 18733/T1 age/Cor/CoreMain.cpp:256 ]: Passenger core running in multi-application mode.
[ N 2019-03-11 07:33:39.7577 18733/T1 age/Cor/CoreMain.cpp:1014 ]: Passenger core online, PID 18733
[ N 2019-03-11 07:33:42.4774 18733/Ta age/Cor/SecurityUpdateChecker.h:519 ]: Security update check: no update found (next check in 24 hours)
[ N 2019-03-11 07:33:44.0159 18759/T1 age/Wat/WatchdogMain.cpp:1366 ]: Starting Passenger watchdog...
[ N 2019-03-11 07:33:44.0536 18762/T1 age/Cor/CoreMain.cpp:1339 ]: Starting Passenger core...
[ N 2019-03-11 07:33:44.0538 18762/T1 age/Cor/CoreMain.cpp:256 ]: Passenger core running in multi-application mode.
[ N 2019-03-11 07:33:44.0625 18762/T1 age/Cor/CoreMain.cpp:1014 ]: Passenger core online, PID 18762
[ N 2019-03-11 07:33:46.7938 18762/T5 age/Cor/SecurityUpdateChecker.h:519 ]: Security update check: no update found (next check in 24 hours)
curl https://23.105.196.112
报错如下:
curl: (7) Failed to connect to 23.105.196.112 port 443: Connection refused
找了很久了原因,觉得是 ssl 的问题,尝试直接访问 http 而不是 https:
curl http://23.105.196.112
,没有反应
wget http://23.105.196.112
结果如下:
--2019-03-11 09:24:16-- http://23.105.196.112/
Connecting to 23.105.196.112:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://23.105.196.112/ [following]
--2019-03-11 09:24:16-- https://23.105.196.112/
Connecting to 23.105.196.112:443... failed: Connection refused.
我完全按照 passenger 的文档和参照社区的几篇文章来部署,但现在不知道是自己哪里出了问题
按照 passenger 的文档部署了三次,检查了确认和上面步骤一样且没报错。现在我检查实在发现不了问题所在,部署这个网站花了三天时间,我也在搜索了很多关于 nginx 和 passenger 成功启动但不能正常访问的问题。都没有得到解决方法。
我现在认为是 nginx 配置 ssl 的问题,但我看了很多认证 ssl 都需要域名,我只是尝试一下部署在网上,没准备买域名,而且看了前面连接给的方法也可以用 ip 直接访问。当然我分析的可能完全是错的。
希望各位高手能给出一点建议让我继续下去。