我在Ubuntu 14.04 VPS上遇到nginx服务器问题。我成功安装了Passenger(最新)和Nginx。现在我创建了测试Rails应用程序(rails 4.2.3)。我的应用程序的路径是/ home / testapp / public;
在/opt/nginx/conf/nginx.conf我有这个设置:
user root;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
passenger_root /usr/local/rvm/gems/ruby-2.2.1/gems/passenger-5.0.15;
passenger_ruby /usr/local/rvm/gems/ruby-2.2.1/wrappers/ruby;
include mime.types;
default_type application/octet-stream;
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
root /home/testapp/public;
passenger_enabled on;
rails_env production;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
server {
listen 8001;
server_name testapp.com;
passenger_enabled on;
root /home/testapp/public;
location / {
root html;
index index.html index.htm;
}
}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
正如您所看到的,端口80和8001上有两个服务器配置。转到这两个端口我有结果默认的nginx页面。
我没有从Passenger,Nginx,Rails得到任何错误,一切都没问题。
注意:在安装Passenger和nginx模块时,我没有获得站点可用和启用站点的文件夹,所以我在/ opt / nginx / path创建了两个文件。
我需要做些什么才能显示我的rails testapp而不是nginx默认页面?
答案 0 :(得分:2)
在您的端口80,8001配置中删除
location / {
root html;
index index.html index.htm;
}
部分因为这会覆盖root /home/testapp/public;
指令
答案 1 :(得分:0)
这就是我在服务器标签中所需要的全部内容:
server {
listen 80;
server_name localhost;
passenger_enabled on;
root /home/testapp/public;
rails_env production;
}
还删除了:
location / {
root html;
index index.html index.htm;
}