Snippets Collections
sudo su
printf "<user>:$(openssl passwd -apr1 <your password>)\n" >> /etc/nginx/.htpasswd
;MainWP Requriement - cURL timeout
default_socket_timeout = 300
;END MainWP Requriement
FROM node:16-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install

# Rebuild the source code only when needed
FROM node:16-alpine AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
RUN rm -f next.config.js
COPY ./next.config.local.js ./next.config.js
RUN rm -f .env.production && mv .env.local .env.production
RUN npm run build

# Production image, copy all the files and run next
FROM node:16-alpine AS runner

RUN apk --update --no-cache --virtual build-dependencies add \
  nginx

RUN npm install -g pm2

WORKDIR /app

ENV NODE_ENV production
ENV APP_ENV local
ENV NEXT_TELEMETRY_DISABLED 1

COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/pages ./pages
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/ecosystem.config.js ./ecosystem.config.js
# RUN cd /app/data/en-gb/products && cp me-888-marathon-ultra.json me-888-marathon-ultra-oth.json

COPY docker/nginx.conf /etc/nginx/nginx.conf

COPY docker/entrypoint.sh /usr/local/bin/entrypoint
RUN chmod +x /usr/local/bin/entrypoint

ENTRYPOINT [ "entrypoint" ]

CMD ["nginx"]


# Create a file app/docker/entrypoint.sh
# ------------------------------------------
#!/bin/sh

set -e

# pm2-docker --max-memory-restart 300M --deep-monitoring start "npm start" & nginx

pm2-runtime ecosystem.config.js & nginx


## Create a file in app/ecosystem.config.js

module.exports = {
  apps: [
    {
      name: "app",
      cwd: "/app",
      script: "node_modules/next/dist/bin/next",
      args: "start",
      max_memory_restart: "900M"
    }
  ]
};
server{
    :
    
    location / {
      # First attempt to serve request as file, then
      # as directory, then fall back to displaying a 404.
      try_files $uri $uri/ @extensionless-php;
    }

    location @extensionless-php {
      if ( -f $document_root$uri.php ) {
        rewrite ^ $uri.php last;
      }
      return 404;
    }
    
    :
}
server {
    listen 80;
    listen [::]:80;
    server_name example.com;
    root /srv/example.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/php8.0-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }
 
    location ~ /\.(?!well-known).* {
        deny all;
    }
}
certbot certonly --standalone -d kfc-copypaste-api.the-lion.com --staple-ocsp -m josuedjh456@gmail.com --agree-tos
grep -inRsH "Text to be searched" apps/
## Dockerfile
FROM php:7.4-fpm

# Arguments defined in docker-compose.yml
ARG user
ARG uid

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
    chown -R $user:$user /home/$user

# Set working directory
WORKDIR /var/www

USER $user

## EOF Dockerfile

## docker-compose.yaml
# Docker compose for PHP, Composer and nginx
# Check Dockerfile to create app image, PHP 7.4 and Composer
# Run: docker-compose up
# After mounted, open container cli 
# 
# Update laravel packages:
##### composer update
# Restart container to apply nginx configuration
##### docker compose restart 

version: "3.7"
services:
  app:
    build:
      args:
        user: sammy
        uid: 1000
      context: ./
      dockerfile: Dockerfile
    image: my-app
    container_name: myapp-php
    restart: always
    working_dir: /var/www/
    volumes:
      - ./:/var/www
    networks:
      - webdev

  nginx:
    image: nginx:alpine
    container_name: myapp-nginx
    restart: unless-stopped
    ports:
      - 8000:80
    volumes:
      - ./:/var/www
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
    networks:
      - webdev

networks:
  webdev:
    driver: bridge
    
## EOF docker-compose.yml

## create a nginx.conf file in the root of your app
## nginx.conf

server {
    listen 80;
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/public;
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }
}

## EOF nginx.conf


Run: 
docker-compose up

When container is up open container console (cli)
composer update
docker compose restart

map $http_origin $allow_origin {
    ~^https?://(.*\.)?my-domain.com(:\d+)?$ $http_origin;
    ~^https?://(.*\.)?localhost(:\d+)?$ $http_origin;
    default "";
}

server {
    listen 80 default_server;
    server_name _;
    add_header 'Access-Control-Allow-Origin' $allow_origin;
    # ...
}
# start a web service using nginx
service nginx start

# check nginx landing page using curl
curl http://localhost:80
server {
  ...
    location /wp {
        alias /home/user/www/.../wordpress/;
        index index.php index.html index.htm;
        try_files $uri $uri/ /wp/index.php?$is_args$args;
    }
    location ~ \.php$ {
        root /home/user/www/.../wordpress/;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_split_path_info ^/wp(/.+\.php)(.*)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

  ...
}
star

Wed Nov 22 2023 22:32:23 GMT+0000 (Coordinated Universal Time)

#nginx #ssl
star

Thu Jun 08 2023 14:34:22 GMT+0000 (Coordinated Universal Time)

#wordpress #config #nginx #apache #php
star

Mon Nov 28 2022 16:14:55 GMT+0000 (Coordinated Universal Time)

#nginx #nextjs #dockerfile
star

Mon Aug 29 2022 18:45:16 GMT+0000 (Coordinated Universal Time)

#php #nginx
star

Tue Jun 21 2022 05:01:33 GMT+0000 (Coordinated Universal Time) https://laravel.com/docs/9.x/deployment

#php #laravel #nginx
star

Mon Apr 11 2022 14:11:19 GMT+0000 (Coordinated Universal Time)

#linux #ubuntu #nginx
star

Mon Apr 11 2022 13:41:23 GMT+0000 (Coordinated Universal Time)

#linux #ubuntu #nginx
star

Tue Nov 16 2021 11:37:21 GMT+0000 (Coordinated Universal Time)

#docker #nginx #php #phpfm
star

Wed Aug 11 2021 14:45:09 GMT+0000 (Coordinated Universal Time)

#nginx #cors
star

Sat Apr 10 2021 05:57:14 GMT+0000 (Coordinated Universal Time)

#linux #nginx
star

Sat Feb 13 2021 14:25:20 GMT+0000 (Coordinated Universal Time)

#nginx #wordpress

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension