AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 873925
Accepted
David
David
Asked: 2017-09-16 13:46:21 +0800 CST2017-09-16 13:46:21 +0800 CST 2017-09-16 13:46:21 +0800 CST

如何配置 NGINX 位置以在服务器的子目录中提供 Codeigniter RESTful API?

  • 772

我有以下目录结构:

mysite.com
- /api (codeigniter RESTful API Server)
- /app (backbonejs app)

我正在尝试配置 NGINX 以将 mysite.com/api* 的所有请求指向 api 目录并使用 Codeigniter 的设置。

如果 CI 在根目录中,我发现的所有内容都可以正常工作。但是,当您尝试将其放在子目录中时,它会失败。

这是我目前拥有的:

server {
        listen 80;
        server_name local.mysite.com;
        root /Users/me/Sites/mysite;
        autoindex on;
        index index.html index.php;

        location /api {
            try_files $uri $uri/ /api/index.php;

            location ~ \.php$ {
                root /Users/me/Sites/mysite/api;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
            }


        }



    }

这样做只会给我一个“找不到文件”错误。甚至没有合适的 nginx 404。如何在服务器的子目录中为 CodeIgniter 配置 NGINX?

谢谢!

linux
  • 1 1 个回答
  • 2313 Views

1 个回答

  • Voted
  1. Best Answer
    David
    2017-09-16T14:02:24+08:002017-09-16T14:02:24+08:00

    对于其他试图解决这个问题但由于还没有答案而失败的人,这里有一个超级简单的设置:

    140     server {
    141         listen 80;
    142         server_name local.mysite.com;
    143         root /Users/me/Sites/mysite;
    144         autoindex on;
    145         index index.html index.php;
    146
    147         location /api {
    148             try_files $uri $uri/ /api/index.php$args;
    149
    150         }
    151
    152         location ~ \.php$ {
    153             fastcgi_pass 127.0.0.1:9000;
    154             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    155             include fastcgi_params;
    156         }
    157
    158
    159
    160     }
    
    • 0

相关问题

  • Linux 主机到主机迁移

  • 如何在 Linux 机器上找到有关硬件的详细信息?

  • 如何在 Linux 下监控每个进程的网络 I/O 使用情况?

  • 在 RHEL4 上修改 CUPS 中的现有打印机设置

  • 为本地网络中的名称解析添加自定义 dns 条目

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve