【问题标题】:Azure web app laravel api - nginx error 404Azure Web 应用程序 laravel api - nginx 错误 404
【发布时间】:2022-10-01 09:45:12
【问题描述】:

我在我的 azure Web 应用程序上收到了 404 Not Found nginx/1.14.2。 我正在使用连接到 azure MySQL 数据库的 azure Web 应用服务。

我找不到导致我的 API 路由响应为 404 错误的问题。

我检查了大多数答案,但我并没有真正明白,因为我是 azure 服务器配置的新手。 我使用 ssh 访问我的文件,但我不知道如何解决这样的问题......

这些是我的文件,如下所示: .htaccess 在公共场合是:

Options -Indexes
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

<Files .env>
    Order allow,deny
    Deny from all
</Files>

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

默认在/etc/nginx/sites-enabled

server {
    #proxy_cache cache;
        #proxy_cache_valid 200 1s;
    listen 8080;
    listen [::]:8080;
    root /home/site/wwwroot/public;
    index  index.php index.html index.htm;
    server_name  example.com www.example.com;

    location / {
        index  index.php index.html index.htm hostingstart.html;
    }
    location /snow/api {
        root /var/www/html/snow/pubic;
        try_files $uri $uri/ /index.php?$query_string;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /html/;
    }

    # Disable .git directory
    #
    location ~ /\\.git {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Add locations of phpmyadmin here.
    #
location ~ [^/]\\.php(/|$) {
        fastcgi_split_path_info ^(.+?\\.php)(|/.*)$;
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param HTTP_PROXY \"\";
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_intercept_errors on;
        fastcgi_connect_timeout         300;
        fastcgi_send_timeout           3600;
        fastcgi_read_timeout           3600;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }
} ```

What am I missing?

  • 我在 laravel azure web app 上有同样的问题。你找到解决办法了吗?
  • @nelsonym 不幸的是没有

标签: php laravel azure nginx


【解决方案1】:
  • 404 错误基本上意味着您或您的访问者的网络浏览器能够成功连接到网站服务器或主机。但是,无法找到所请求的资源,例如文件名或特定 URL。
  • 如果您收到404 Not Found Nginx error 并且您已经仔细检查了该资产是否存在于您的服务器上,那么您的配置文件可能是问题所在。要验证这一点,请打开您的 nginx.conf 文件并查看您的站点是否使用了正确的根文件夹路径。
  • 它可能显示404 Not Found Nginx error,因为路径不正确。此外,请仔细检查配置文件的重写规则,以确保它们没有配置错误。

检查这个类似的 SO 线程解决方法 - https://stackoverflow.com/a/70970178

参考 -

  1. PHP 8 on Azure App Service
  2. Deploying PHP 8.0 applications with Azure App Service

【讨论】:

    【解决方案2】:

    以防万一它帮助其他任何人使用 azure 中的 Linux 应用服务出现 404 错误:

    显然,当 Laravel 出错时,nginx 会返回 404。你会发现的唯一证据是通过 ssh 进入实例并查看 Laravel 存储文件夹日志。

    【讨论】:

      猜你喜欢
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 2020-07-18
      • 2017-11-22
      • 1970-01-01
      • 2017-12-30
      相关资源
      最近更新 更多