search

Home  >  Q&A  >  body text

nginx encounters 404 error after upgrading Azure App Service to PHP 8.1

I'm trying to move a CakePHP application from PHP 7.4 to Azure App Service using PHP 8.1. I'm having trouble figuring out the nginx configuration required to make it work.

I took a basic nginx configuration, added changes from the CakePHP book, and injected the configuration file during startup (cp /home/default /etc/nginx/sites-enabled/default).

I keep getting 404 errors except for the root page. On the index page, layout issues can also occur as these links also return 404s.

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

    #location / {            
    #    index  index.php index.html index.htm hostingstart.html;
    #}

    # 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;
    }

    #added from CakePHP book
    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    #added from CakePHP book
    location ~ .php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_intercept_errors on;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    # 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;
    #}
}


P粉988025835P粉988025835317 days ago497

reply all(1)I'll reply

  • P粉409742142

    P粉4097421422024-01-02 09:18:57

    I failed to add the service nginx restart command after the copy. It seems to be working now.

    reply
    0
  • Cancelreply