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
    • 最新
    • 标签
主页 / user-517981

Madushan Perera's questions

Martin Hope
Madushan Perera
Asked: 2021-08-12 19:28:26 +0800 CST

Nginx - 更改特定 url 的根文件夹会产生 404 错误

  • 1

我正在尝试为任何人通过mydomain.com/game/adminurl 安排一个位置块,确保用于提取内容的 nginx 服务器存在于/var/www/html/my-cakephp-app/目录中。我的应用程序是使用 cakephp 框架构建的,其目录结构如下所示:

  • /var/www/html/my-cakephp-app/
    • 行政
      • 配置
      • 安慰
      • 控制器
      • 看法
      • webroot(该目录下存在App入口点index.php文件)

我也有位于/var/www/html目录中的静态 html/css 网站。所以任何有mydomain.comurl 的人也可以看到该网站。

这是我当前的 nginx 服务器块:

server {
    listen 80;
    listen [::]:80;

    root /var/www/html;

    index index.html index.htm index.php;

    server_name mydomain.com;

    location / {
        try_files $uri $uri/ =404;
    }
    
    location /game/admin {
            return 301 /game/admin/;
    }

    location /game/admin/ {

                root /var/www/html/my-cakephp-app/admin/webroot;
                try_files $uri $uri/ /game/admin/index.php$is_args$args;
  
                location ~* \.php(/|$) {
                  include snippets/fastcgi-php.conf;
                  fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               } 

    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

使用此设置,我的静态网站可以正常工作。但是 cakephp 应用程序在浏览器中给出 404 not found 错误。nginx/error.log 中没有任何错误。

但是当我使用以下 nginx 配置运行时,我的应用程序运行良好。但我必须摆脱我的 html/css 网站。我计划用 wordpress 网站升级 html/css 应用程序。所以我应该能够以父级身份运行 wordpress 网站。

server {
    listen 80;
    server_name mydomain.com;
    root /var/www/html/my-cakephp-app/admin/webroot;
    
    index index.html index.htm index.php;
 
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
        autoindex on;
    }
    
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
    
    location ~ /\.ht {
        deny all;
    }
}

我想不出我在第一个服务器块上做错了什么。任何建议都会非常有帮助。

web-server web-hosting nginx
  • 1 个回答
  • 1296 Views

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