[DOCKER] webserver apache php56 - fourslickz/notes GitHub Wiki

HOST WEB SERVER

NGINX VHOST

server {
    listen 80;
    server_name member.midtou.com;

    # Logging
    access_log /var/log/nginx/member.midtou.com.access.log;
    error_log /var/log/nginx/member.midtou.com.error.log;

    # Max upload
    client_max_body_size 20M;

    # =========================
    # SECURITY HEADERS
    # =========================
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-XSS-Protection "1; mode=block" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;

    # =========================
    # MAIN PROXY
    # =========================
    location / {
        proxy_pass http://127.0.0.1:8080;

        proxy_http_version 1.1;

        # Header penting
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $host;

        # Laravel / HTTPS detection
        proxy_set_header HTTPS on;

        # WebSocket support (kalau ada)
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        # Timeout (hindari 502)
        proxy_connect_timeout 60s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;

        # Buffer tuning
        proxy_buffering on;
        proxy_buffers 16 16k;
        proxy_buffer_size 32k;
    }

    # =========================
    # STATIC FILE CACHE
    # =========================
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff|woff2|ttf|svg)$ {
        expires 30d;
        access_log off;
        add_header Cache-Control "public";
    }

    # =========================
    # BLOCK SENSITIVE FILES
    # =========================
    location ~ /\.(env|git|htaccess|htpasswd) {
        deny all;
    }
}

DOCKER

Dockerfile

FROM php:5.6-apache

# 🔧 Fix repo Debian Stretch (EOL)
RUN sed -i 's|deb.debian.org|archive.debian.org|g' /etc/apt/sources.list \
    && sed -i 's|security.debian.org|archive.debian.org|g' /etc/apt/sources.list \
    && sed -i '/stretch-updates/d' /etc/apt/sources.list \
    && echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/99no-check-valid

# 🔥 Allow insecure repo (WAJIB untuk archive)
RUN echo 'Acquire::AllowInsecureRepositories "true";' > /etc/apt/apt.conf.d/99insecure \
    && echo 'Acquire::AllowDowngradeToInsecureRepositories "true";' >> /etc/apt/apt.conf.d/99insecure

# Enable mod_rewrite
RUN a2enmod rewrite

# ✅ Install dependency
RUN apt-get update && apt-get install -y --allow-unauthenticated \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    libxml2-dev \
    unzip curl \
    && rm -rf /var/lib/apt/lists/*

# ✅ Configure GD (khusus PHP 5.6)
RUN docker-php-ext-configure gd \
    --with-freetype-dir=/usr/include/ \
    --with-jpeg-dir=/usr/include/

# ✅ Install PHP extensions
RUN docker-php-ext-install \
    mysqli pdo pdo_mysql mbstring zip gd

# Allow .htaccess
RUN sed -i 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf

WORKDIR /var/www/html

docker-compose.yml

services:
  apache:
    build: .
    container_name: apache_php56
    ports:
      - "127.0.0.1:8080:80"
    volumes:
      - /var/www/html/app:/var/www/html