Skip to content

Instantly share code, notes, and snippets.

@schakko
Last active January 17, 2024 08:06
Show Gist options
  • Save schakko/8076888f98fed2b1f4cc2448d44a3057 to your computer and use it in GitHub Desktop.
Save schakko/8076888f98fed2b1f4cc2448d44a3057 to your computer and use it in GitHub Desktop.
Adjusted nginx.conf to make Laravel 9 and Laravel 10 apps with PHP 8.0, 8.1 and 8.2 features runnable on Azure App Service
server {
# adjusted nginx.conf to make Laravel 9 and Laravel 10 apps with PHP 8.0, 8.1 and 8.2 features runnable on Azure App Service
# @see https://laravel.com/docs/10.x/deployment
# @see https://laravel.com/docs/9.x/deployment
listen 8080;
listen [::]:8080;
root /home/site/wwwroot/public;
index index.php;
server_name example.com www.example.com;
location / {
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/;
}
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 $realpath_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;
}
}
@nicojmb
Copy link

nicojmb commented Dec 15, 2021

Hi, i tried this config to use in Codeigniter4 and "Home" page works, but other pages get 404 error on nginx.
¿Have you custom config for AppService Linix PHP 8.0 an Codeigniter 4.1.5?

@schakko
Copy link
Author

schakko commented Dec 15, 2021

@nicojmb
Copy link

nicojmb commented Dec 15, 2021

@schakko Yes, and after following the tutorial now the homepage works, but other routes olways get 404 nginx not found

@schakko
Copy link
Author

schakko commented Dec 15, 2021

@nicojmb Not sure about CodeIgniter. Accordingly to https://codeigniter4.github.io/userguide/installation/running.html you have to set

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

Normal .php files should throw a 404 but not routes with missing .php extensions.

@nicojmb
Copy link

nicojmb commented Dec 15, 2021

@schakko Thank for your help.

I dont know why but AppService not detect my php file changes and i think that i retrieve some type of cache when go to specific route.

@schakko
Copy link
Author

schakko commented Dec 15, 2021

@nicojmb Ah yes. Code changes are not immediately to the runtime environment. nginx has to be manually restarted and it depends in which of the deployment directories you made the code changes. AppService Log Stream is your friend ;-)

@nicojmb
Copy link

nicojmb commented Dec 15, 2021

@schakko wow ,with AppService Log Stream find the problem.

I've a 500 error in my code, so in nginx have a redirect error codes to /"50x.html" that of course this path do not existt and get 404 from nginx.

commented de error redirect and get codeigntier errors!

Thanks so much.

@schakko
Copy link
Author

schakko commented Dec 15, 2021

@nicojmb You are welcome!

@chrisscalzo
Copy link

Thanks for sharing this script. I've used it manually to get my Laravel 8 site running up on Azure App Service with PHP 8. The issue I am having is when I restart my app service the startup script doesn't appear to be firing. In the Log stream I see:

[ERROR] /opt/startup/startup.sh: 13: /opt/startup/startup.sh: /home/site/repository/startup.sh: not found

My Azure App Service configuration setting is pointing to "/home/site/repository/startup.sh" for the startup script. When I run things manually via the command line via SSH (1) Overwriting the defualt conf file in avaiable-site and (2) reloading Reloading nginx to apply the new conf) the web app works and pages are served. Any idea why Azure App Service wouldn't be finding the script (I have double checked that its there in "/home/site/repository".

@vienleidl
Copy link

Thanks for sharing this script. I've used it manually to get my Laravel 8 site running up on Azure App Service with PHP 8. The issue I am having is when I restart my app service the startup script doesn't appear to be firing. In the Log stream I see:

[ERROR] /opt/startup/startup.sh: 13: /opt/startup/startup.sh: /home/site/repository/startup.sh: not found

My Azure App Service configuration setting is pointing to "/home/site/repository/startup.sh" for the startup script. When I run things manually via the command line via SSH (1) Overwriting the defualt conf file in avaiable-site and (2) reloading Reloading nginx to apply the new conf) the web app works and pages are served. Any idea why Azure App Service wouldn't be finding the script (I have double checked that its there in "/home/site/repository".

It seems to me that it might be caused by your startup script which was modified on Windows machine with CRLF. So, the Azure PHP App Service could not recognize that script. Could you try to convert it to LF with Notepad++ or VS Code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment