JSecurity
JSecurity

Reputation: 185

Azure App Service for Container: Expose TCP custom port 9000 for FPM

I’m encountering a major issue with Azure Container Apps and am considering switching to Azure App Service for Containers.

I have two Docker images: one for Nginx and one for FPM. My plan is to deploy Nginx on one Azure App Service and FPM on another.

However, I don’t understand why Nginx can't connect to FPM. I set WEBSITES_PORT to 9000, but I still get the following error:

upstream timed out (110: Operation timed out) while connecting to upstream, client: .... upstream: "fastcgi://localIP:9000"

Do you have any insights on this? Do I need to do some further steps as FPM exposes TCP listener and not a HTTPS ? Thanks you in advance.

Upvotes: 0

Views: 51

Answers (1)

Sampath
Sampath

Reputation: 3533

According to this documentation, your container app cannot be configured to run exclusively on either port 443 or 80 for TCP.

enter image description here

Modify nginx.conf:

server { listen 80;
...
...
}

Create Dockerfiles for Nginx and PHP-FPM Containers

Dockerfile for Nginx (nginx/Dockerfile)

# Use lightweight Alpine Nginx
FROM nginx:1.14-alpine

# Set working directory
WORKDIR /srv/www/app

# Remove default nginx config
RUN rm /etc/nginx/conf.d/default.conf

# Copy Nginx config file into container
COPY nginx.conf /etc/nginx/conf.d/default.conf

# Expose port 80 for HTTP
EXPOSE 80

# Start Nginx
CMD ["nginx", "-g", "daemon off;"]

php/Dockerfile:

# Use PHP 7.2 with FPM
FROM php:7.2-fpm

# Set working directory
WORKDIR /srv/www/app

# Install dependencies
RUN apt-get update -y && \
    apt-get install -y \
        openssl \
        zip \
        unzip \
        git \
        libmcrypt-dev

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Install PHP extensions
RUN docker-php-ext-install pdo pdo_mysql mbstring

# Expose PHP-FPM on port 9000 for TCP
EXPOSE 9000

# Start PHP-FPM
CMD ["php-fpm"]

nginx/nginx.conf:

server { 
    listen 80;

    server_name localhost;

    root /srv/www/app; 
    index index.php;

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

    location ~ [^/]\.php(/|$) { 
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }

        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

        fastcgi_pass fpm-app:9000;  # Use service name
        fastcgi_index index.php;
    }
}

enter image description here

For more details, refer to this SO post worked by me and git.

Upvotes: 0

Related Questions