【问题标题】:Fix 404 nginx and thin?修复 404 nginx 和瘦?
【发布时间】:2019-05-14 18:00:11
【问题描述】:

我目前正在 ubuntu 服务器上安装我的应用程序。我想知道为什么,当我尝试访问我的 API 时,nginx 会返回 404。

我已经配置了thin 和nginx,但我不知道为什么这不起作用,并且作为这个领域的新手我承认我不知道从哪里开始。

我尝试更改瘦配置和 nginx 配置,但没有任何效果。

精简配置

user: www-data
group: www-data
pid: tmp/pids/thin.pid
timeout: 30
wait: 30
log: log/thin.log
max_conns: 1024
require: []
environment: production
max_persistent_conns: 512
servers: 1
threaded: true
no-epoll: true
address: 0.0.0.0
port: 3000
daemonize: true
chdir: /home/ubuntu/happer-api
tag: happer-api

Nginx 配置

upstream myapp {
      server 127.0.0.1:3000;
      server 127.0.0.1:3001;
      server 127.0.0.1:3002;
    }
    server {
      listen   80;
      server_name .example.com;

      access_log /home/ubuntu/happer-api/log/access.log;
      error_log  /home/ubuntu/happer-api/log/error.log;
      root     /home/ubuntu/happer-api;
      index    index.html;

      location / {
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header  Host $http_host;
        proxy_redirect  off;
        try_files /system/maintenance.html $uri $uri/index.html $uri.html @ruby;
      }

      location @ruby {
        proxy_pass http://myapp;
      }
    }

我在 EC2 实例上,我使用亚马逊工具打开端口

我的 API 上也有活跃的管理员,但我无法访问它。

【问题讨论】:

    标签: ruby nginx thin


    【解决方案1】:

    对于 Rails 项目,Nginx 根目录应以 public 结尾:

    root     /home/ubuntu/happer-api/public;
    

    您也可以尝试从域名中删除初始点吗?

    `server_name .example.com;`
    

    并删除另外两个以30013002 端口结尾的上游服务器。你的瘦身应该只服务一个!

    【讨论】:

    • 谢谢,但结果相同,但我无法访问我的 API 或 BackAdmin。和细日志什么都不说。
    猜你喜欢
    • 2011-04-10
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-30
    • 1970-01-01
    • 2019-01-22
    • 1970-01-01
    相关资源
    最近更新 更多