Ruby on rails 404未找到-nginx/1.12.2-Rails Api应用程序-路由错误
我无法访问API 我正在使用Nginx和乘客。我正在使用Capistrano部署它 我在Nginx站点中的默认文件可用Ruby on rails 404未找到-nginx/1.12.2-Rails Api应用程序-路由错误,ruby-on-rails,api,nginx,capistrano,passenger,Ruby On Rails,Api,Nginx,Capistrano,Passenger,我无法访问API 我正在使用Nginx和乘客。我正在使用Capistrano部署它 我在Nginx站点中的默认文件可用 ## ## # Default server configuration # server { listen 80; root /var/www/xyz/current/public; # Add index.php to the list if you are using PHP # index index.html index.htm i
##
##
# Default server configuration
#
server {
listen 80;
root /var/www/xyz/current/public;
# Add index.php to the list if you are using PHP
# index index.html index.htm index.nginx-debian.html;
passenger_enabled on;
rails_env staging;
server_name ec2-258-255-77-987.eu-west-2.compute.amazonaws.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
我无法从同一台服务器访问API,并获得404
请帮帮我
编辑
我检查了错误日志,它显示了路由错误
我的应用程序位于var/www/xyz/current
“我的路由”有什么问题?问题在于,您的NGINX没有正确配置以处理应用程序的流量,您仅以现有方式为资产配置了它。您应该添加一个应用程序应该侦听的上游套接字。首先,在
default
文件中添加一个指向应用程序套接字的上游
块:
## Start of file
upstream my_app {
server unix:/tmp/capistrano.passenger.sock fail_timeout=0;
## You can use a HTTP address if you don't want your application listening into sockets.
# server http://127.0.0.1:8000 fail_timeout=0;
}
# other stuff like: server { ...
然后分离用于分离其配置的资产流和应用程序流,并创建一个服务器
范围try\u文件
,包括您的应用程序上游:
server {
# other stuff...
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri $uri/ @my_app;
location @my_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://my_app;
}
# other stuff...
}
不要忘记删除现有的location/{…}
块