Azure web application gets 5XX error after deploy - php

I have a Laravel web application I'm trying to deploy to Azure Web App.
I'm using PHP 8.1 and Laravel 9, I created a resource on Azure, And deployed my web application.
I created nginx config file on /home, with this configuration (from Laravel docs):
server {
listen 80;
listen [::]:80;
server_name MY_WEBAPP_URL;
root /home/site/wwwroot/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
I then set the web app's startup command to the recommended command:
cp /home/default /etc/nginx/sites-enabled/default; service nginx restart
I restarted the web app server, and tried to access it, but I get error 5XX, which says:
:( Application Error
I searched the web, but it seems like there is no solution to properly deploy PHP 8.1 application to Azure.
I tried few different nginx configuration that I saw, but none worked.
Deploying with Docker also has it's own different errors (on Azure only, works fine on local container).

Related

after uploading laravel project to elastic beanstalk API urls dont work and open get api pages show 404

I am a bit new to AWS Elastic Beanstalk I used AWS Elastic Beanstalk to create a PHP 7 deployment for a Laravel project which runs perfectly on my laptop. then uploaded my Laravel project files, edited the .env file
after uploading the Laravel project to elastic beanstalk only the homepage displays but API urls dont work and open get api pages show 404 Not Found error
Even after trying solution on this stack overflow page, the issue still persists
Please advise me on how to make other pages apart from the home page that are currently showing as 404 pages stop showing as 404 pages
=======EDITS=========
here's my EB PHP settings file
its location is
.platform/nginx/conf.d/elasticbeanstalk/laravel.conf
Content below
server {
listen 80;
server_name myrootpathapi-env.eba-ghdkmh8i.us-east-2.elasticbeanstalk.com;
root myrootpathapi-env.eba-ghdkmh8i.us-east-2.elasticbeanstalk.com/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}

nginx consider swagger UI path to index.html as a route path

I have two projects both using identical nginx configurationg, only difference is host name and path to web directory:
server {
listen 80;
server_name {project_host};
root /var/www/{project_path}/web;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_log /var/log/nginx/{project_name}_error.log;
access_log /var/log/nginx/{project_name}_access.log;
error_page 404 /index.php;
sendfile off;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
}
location ~ /\.ht {
deny all;
}
}
both in the web dir has folder docs which has all swagger-ui files with index.html.
All is working fine for project one, I can get access to swagger ui using url prject1/docs/index.html, but in case of project 2 when I going to project2/docs/index.html I'm getting my not found page which should be shown by php when a route is not found. Why in case of app 1 nginx understand that /docs/index.html is not route but in case of app 2 it's considering it as a route instead of path to the file if configurations the same
My web dir structure is (identical for both projects) :
web/
index.php
docs/
index.html
other_swagger_ui_files
Maybe it'll also be useful, both projects are kind of microservices, and locally I have a docker-compose configuration to start and up them, so they both under the same network and using the same Nginx-proxy container and sharing same PHP container, but each of them has own Nginx container (but as I already told they identical and have identical configuration)

Facing redirection issue while setting up Wordpress with Nginx via Amazon API Gateway and Network Load Balancer

Facing redirection issue while setting up Wordpress with Nginx via Amazon API Gateway and Network Load Balancer.
Description:-
We have our main website xyz.com(served by Amazon API Gateway and Load Balancer) and want our blogs to be present on xyz.com/blogs.
So, we have set up Amazon API Gateway and Load Balancer to redirect any request of the for xyz.com/blogs to the EC2 containing Wordpress with Nginx.
Problem:-
The problem that we are facing is, the home page is rendered fine but when we try to render any other page, e.g:- xyz.com/blogs/my-first-post/ or xyz.com/blogs/wp-admin then it gets stuck over there and nothing comes as response. As a part of our initial debugging, we found out that Wordpress is making redirections to the Network Load Balancer url, (which as per our guess) is not accessible and we are not getting any response.
This is how our default nginx conf looks like (/etc/nginx/conf.d/xyz_blogs.conf), which we got from this link => Wordpress|Nginx
# Upstream to abstract backend connection(s) for php
upstream php {
server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9000;
}
server {
## Your website name goes here.
server_name xyz.com;
## Your only path reference.
root /var/www/html;
## This should be in your http block and if it is, it's not needed here.
index index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
How shall we resolve this issue?
A prior thanks for any help given hereby.
Thy this:
upstream php-app { # <-- change name of the upstram
# server unix:/tmp/php-cgi.socket; # <-- Remove this
# List of [IP:Port] OR list of [sockets] not both mixed
server 127.0.0.1:9000;
# server 127.0.0.1:9001; # example
# server 127.0.0.1:9002; # example
}
server {
listen 80 default_server; # <-- Add this line
listen [::]:80 default_server; # <-- Add this line
server_name xyz.com *.xyz.com;
root /var/www/html;
# index index.php; # <-- Will be removed, you app is provided by the socket/port
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location / { # Put this at the end, NGinx apply priority
proxy_pass http://php-app; # Add this line
}
}
Update 1:
update config
...
server_name xyz.com *.xyz.com *.amazonaws.com;
...
Sorry for the late post, but currently we have implemented this using a solution which might not be much scalable. What we have done is we have deployed our website and wordpress in the same machine but in a different containers. So, our website is running in a different container and wordpress is running in a different container but both are present in the same EC2.
And we are using nginx configuration in wordpress to redirect the requests to the fellow container. Currently my nginx configuration looks something like this:
upstream php {
server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9000;
}
server {
listen 80;
server_name xyz.com;
root /var/www/html;
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
index index.php;
location /blog {
try_files $uri $uri/ /blog/index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
}
location / {
rewrite ^/(.*) /$1 break;
proxy_pass http://xyz-container:80;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
It would have been great if somehow we would have been able to deploy wordpress container in a different EC2 and still achieve this.
It will really be helpful and a lot better if someone can suggest a better scalable working solution for the problem with wordpress container in a different EC2.
Thanks.

Configuring adminer with NGINX: "no port in upstream php" error

I have set up MeteorJs application with MongoDB backend in Digital Ocean. I am now trying to set up adminer so I can query MongoDB without opening input ports on my droplet. Everytime I try to reload the nginx settings, I get nginx: [emerg] no port in upstream "php" in /etc/nginx/sites-enabled/admin:32 error.
What am I missing?
/etc/nginx/sites-enabled/admin
server {
listen 80;
server_name 165.227.197.220;
return 301 https://$server_name$request_uri;
}
server {
server_name 165.227.197.220;
listen 443 ssl;
access_log /var/log/nginx/admin.access.log;
error_log /var/log/nginx/admin.error.log;
ssl_certificate /etc/nginx/ssl/admin.crt;
ssl_certificate_key /etc/nginx/ssl/admin.key;
root /var/www/admin;
index adminer.php;
# Get file here https://codex.wordpress.org/Nginx
include global/restrictions.conf;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd/admin;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php;
fastcgi_index adminer.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
/etc/nginx/global/restrictions.conf
# Global restrictions configuration file.
# Designed to be included in any server {} block.
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~ /\. {
deny all;
}
# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
You need to setup an upstream for example using wordpress that is what we have
upstream index_php_upstream {
server 127.0.0.1:8090; # NGINX Unit backend address for index.php with
# 'script' parameter
}
For more about upstream, so can view this article UpStream - Nginx

Laravel 500 error when using with nginx

I have tried a lot of configuration settings for nginx to work with laravel but none of them do. I keep getting a 500 error on my webpage.
example.com is currently unable to handle this request.
server {
listen _:80;
server_name example.com;
root "C:\Users\Administrator\Google Drive\projects\laravel";
index index.php index.html;
log_not_found off;
charset utf-8;
access_log logs/cdn.example.com-access.log ;
location ~ /\. {deny all;}
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
location / {
include mime.types;
}
location = /favicon.ico {
}
location = /robots.txt {
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9054;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I am pretty brand new to laravel and sort of new to nginx, I have all my laravel files in the document root that I just moved from my http://localhost:8000 development server. How can I make it live and make it work with nginx?
I can see wrong configuration in your post. You need to properly setup you web server. You should set public directory as root directory, set write permissions on a storage folder.
So, change this:
root "C:\Users\Administrator\Google Drive\projects\laravel";
To this:
root "C:\Users\Administrator\Google Drive\projects\laravel\public";
And restart your web server.

Categories