skip to Main Content

I build a PHP website with Symfony framework version 6.2 and running on PHP 8.2.
Via Github actions, I managed to deploy it to a Microsoft Azure Web App.

When I visit the default domain, created by the Microsoft Azure Web App, I see a "403 Forbidden, nginx/1.22.1" error message.

Via SSH, I can go to the created Azure Web App to check some settings.

My Symfony website is deployed to the folder /home/site/wwwroot.

This is the default /etc/nginx/nginx.conf:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 10068;
        multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log off;
        error_log /dev/stderr;

        ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

I’m pretty sure I need to change the nginx.conf configuration like explained in the Symfony documentation:
https://symfony.com/doc/current/setup/web_server_configuration.html#nginx

But I have no clue where I can add this extra configuration, because the nginx.conf file will be overwritten by every deploy.
Even when I manually change the configuration file, it doesn’t work.

Can someone point me into the right direction?

2

Answers


  1. Chosen as BEST ANSWER

    Thanks to @DragonBe, I found out that I had to change my nginx configuration in the file /etc/nginx/sites-available/default.

    I created a file /home/site/wwwroot/nginx.default in the root of my Symfony project:

    server {
        listen 8080;
        listen [::]:8080;
        root /home/site/wwwroot/public;
        index index.php index.html index.htm;
        port_in_redirect off;
    
        location / {
            try_files $uri $uri/ /index.php$is_args$args;
        }
    
        # Disable .git directory
        location ~ /.git {
            deny all;
            access_log off;
            log_not_found off;
        }
    
        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;
                fastcgi_index index.php;
            }
    
        location ~ .php$ {
            return 404;
        }
    
        error_log /var/log/nginx/project_error.log;
        access_log /var/log/nginx/project_access.log;
    }
    

    After the deploy with Github Actions, I run this command:

    cp /home/site/wwwroot/nginx.default /etc/nginx/sites-available/default && service nginx restart
    

    I hope this will help other Symfony websites with their deployment to an Azure Web App.


  2. You’re thought process is correct, though you’re looking at the wrong configuration file. The file that should be modified is /etc/nginx/sites-available/default.

    For your second issue, where the settings are being overwritten, the solution is to use the command line instruction.

    cp nginx.default /etc/nginx/sites-available/default && service nginx restart
    

    I have a full article about it on https://www.azurephp.dev/2021/09/php-8-on-azure-app-service/ if you want to learn more.

    Good luck 🍀

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search