Issue:
Facing challenges with Nginx configuration for serving static files in Google Cloud Flexible Environment with PHP 8.1 runtime.
Observations:
Solution:
By substituting the default nginx.conf file with a customized version, I successfully enabled the serving of static files.
To overwrite the entire nginx.conf file, replace nginx_conf_include: nginx-app.conf with nginx_conf_override: nginx.conf, where nginx.conf is the custom configuration file. Copy and paste the existing nginx.conf file from the layers/google.php.webconfig/webconfig/ directory and modify it according to your needs.
app.yaml (sample)
runtime: php # The name of the runtime environment that is used by your app.
env: flex # Select the flexible environment.
runtime_config:
operating_system: "ubuntu18" # The version of the operating system to use.
runtime_version: "8.1" # The version of PHP to use.
document_root: public
front_controller_file: index.php
nginx_conf_override: nginx.conf # Instead of nginx_conf_include: nginx-app.conf
...
configuring nginx (sample)
server {
...
root /workspace/public;
# commented out: rewrite ^/(.*)$ /index.php$uri;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
...
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 10m;
access_log off;
etag on;
add_header Cache-Control "public";
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
expires 10m;
access_log off;
etag on;
add_header Cache-Control "public";
}
...
}
Questions:
Have others encountered the same directory layout change when attempting to upgrade to a newer PHP runtime version?
Upon uploading the customized NGINX version, I've noticed the absence of the layers/google.php.webconfig/ directory. Why is this the case, considering that my custom NGINX file is being read correctly?
Could someone provide an overview of the container structure typically built using buildpacks?
What are the potential issues associated with overwriting the nginx.conf file?
Why was the default configuration set to pass everything through index.php?
Documentation:
App Engine Flexible - PHP runtime documentation
Solved! Go to Solution.
@tasos wrote:Solution:
By substituting the default nginx.conf file with a customized version, I successfully enabled the serving of static files.
This seems to be an issue with all versions of php. See my post here:
https://www.googlecloudcommunity.com/gc/Serverless/GAE-Flexible-PHP-8-2-Runtime-Bug/td-p/720812
Today, I just encountered this same issue moving an older app from 7.3 to 7.4.
It's an issue of 7.4 > the nginx conf has been changed.
I'm having this same problem. what's missing in the ... portions of that nginx file?
did you just copy the original and essentially comment out the one line?
Look at the php8.x automatically generated nginx conf files, and the php7.x nginx conf files and compare them. Then modify the php8.x nginx configuration according to your project needs.
You can read more on:
Nginx - Serving static content
Nginx-Docs
Yes I am having the same issue - I reported this issue late last year and the Google support staff told me to come to the forums here so others can solve the problem for me. The only solution is to overwrite the nginx.conf - you can't rely on google support. Basically same solution as yourself.
Hi, I am upgrading also from 7.3 to 8.1 (Laravel) and encountered the same problem, a solution that does not require substituting the whole configuration is to use this nginx-app.conf file and it should work.
Now I have another problem and that is that I cannot use the php artisan optimize command as it does not take the env_variables from the app.yaml for some reason (I use the command in the post-install-cmd section of composer.json when deploying), in 7.3 it worked fine.
I believe just modifying nginx-app.conf shouldn't work because the line
rewrite ^/(.*)$ /index.php$uri;
at the start of nginx.conf takes precedence over it.
It seems that your problem is on the app.yaml file. You probably have mistyped something when you made changes to it. Make sure it is formatted properly before deploying.
@tasos wrote:Solution:
By substituting the default nginx.conf file with a customized version, I successfully enabled the serving of static files.