Sign inSign up

martadinata666/nginx

By martadinata666

Updated almost 3 years ago

php-fpm + nginx, with most common used modules

Image
0

3.1K

martadinata666/nginx repository overview

Nginx with user 1000 (alpine) support

nginx

pipeline status

Supported tags

  • latest
  • mainline-fpm
  • mainline-fpm8.1
  • mainline-fpm8.0

Usage

  web:
   image: registry.gitlab.com/dedyms/nginx:alpine
   container_name: web
   volumes:
     - /path/to/your/web:/var/www/html
   ports:
     - 4040:4040
     - 4443:4443
Additional info

On mainline doesn't brinng php-fpm embeded, you must setup php-fpm container and sync the volume mount, to use this image or use :mainline-fpm tag. Default config attached show default index.php is located in /var/www/html/public instead /var/www/html this behaviour to enable the usability of webapps that usually has index.php in public folder.

SSL Info

SSL generated from debian using ssl-cert, you can overwrite ssl by config or mounts.

 ssl_certificate /etc/ssl/localcerts/nginx.pem;
 ssl_certificate_key /etc/ssl/localcerts/nginx.key;

Overwriting default config

As nginx as cant do different ip and port from host and container, it recomended to create your own config to match ip and port.

# At top level, mean the most left side, in line with **services:** ,** volumes:** or networks:**
configs:
  nginx-default.conf:
    file: ./nginx-default.conf

Then in container definition include the config

web:
    image: registry.gitlab.com/dedyms/ampache:git-fpm
    environment:
      - . . . . .
    ports:
      - . . . . .
    configs:
      - source: nginx-default.conf
        target: /etc/nginx/conf.d/default.conf
        uid: "1000"
        gid: "1000"
    volumes:
      - . . . . . 
    restart: unless-stopped

Config default

#/etc/nginx/conf.d/default.conf
# Default server configuration
#
server {
        listen 4040 default_server;
        listen 4443 ssl default_server;
        
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        ssl_certificate /etc/ssl/localcerts/nginx.pem;
        ssl_certificate_key /etc/ssl/localcerts/nginx.key;
  
        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;

        root /var/www/html/public;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name HOST_IP_ADDR;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        location ~ \.php$ {
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
               fastcgi_pass fpm:9000; #fpm is the name of fcgi server, it depends on the container name.
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
               deny all;
        }
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

xdebug image

xdebug images created as my need to develop php and do some debugging with codeserver

xdebug.ini

Override xdebug.client_host as you need, use IP but need expose port 9003 or use container name.

zend_extension=xdebug

[xdebug]
xdebug.mode=debug
xdebug.client_host=192.168.0.2
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.log=/dev/stdout
error_reporting.ini

Just make php throw err on everything

error_reporting=E_ALL
docker compose for xdebug
web:
    image: martadinata666/nginx:xdebug
    volumes:
      - ./htdocs:/var/www/html #webroot
      - ./xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini #mount xdebug.ini
      - ./error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini #mount error_reporting.ini
    ports:
      - 20000:80
    networks:
      - xdebug

networks:
  xdebug:
    name:xdebug
On execution of php script check the docker logs on php execution script.
[23] Log opened at 2022-03-16 02:31:36.375724
[23] [Step Debug] INFO: Connecting to configured address/port: 192.168.0.2:9003.
[23] [Step Debug] INFO: Connected to debugging client: 192.168.0.2:9003 (through xdebug.client_host/xdebug.client_port). :-)
[23] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/index.php" language="PHP" xdebug:language_version="8.0.16" protocol_version="1.0" appid="23"><engine version="3.1.3"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2022 by Derick Rethans]]></copyright></init>
[23] [Step Debug] <- feature_set -i 1 -n resolved_breakpoints -v 1
[23] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="resolved_breakpoints" success="1"></response>
[23] [Step Debug] <- feature_set -i 2 -n notify_ok -v 1
[23] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="notify_ok" success="1"></response>
[23] [Step Debug] <- feature_set -i 3 -n extended_properties -v 1
[23] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="extended_properties" success="1"></response>
[23] [Step Debug] <- breakpoint_set -i 4 -t exception -x *
[23] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="4" id="230001" resolved="resolved"></response>
[23] [Step Debug] <- run -i 5
127.0.0.1 -  16/Mar/2022:09:31:36 +0700 "GET /index.php" 200
[23] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="5" status="stopping" reason="ok"></response>
[23] [Step Debug] <- stop -i 6
[23] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="6" status="stopped" reason="ok"></response>
[23] Log closed at 2022-03-16 02:31:36.613532
192.168.0.15 - - [16/Mar/2022:09:31:36 +0700] "GET / HTTP/1.1" 200 38 "-" "Mozilla/5.0 (X11; Ubuntu; Linux aarch64; rv:97.0) Gecko/20100101 Firefox/97.0" "-"
[24] Log opened at 2022-03-16 02:31:36.974521

code-server launch.json

For code-server launch.json, we only need the listen part

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": 
            {
                "/var/www/html":"${workspaceRoot}" # I also mount the `./htdocs:/var/www/html #webroot`
            }
        }
    ]
}
Sample of full compose
version: "3.5"
services:
  web:
    image: martadinata666/nginx:xdebug
    volumes:
      - ./htdocs:/var/www/html
      - ./xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
      - ./error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
    ports:
      - 20000:80
    networks:
      - code-server
    deploy:
      placement:
        constraints: [ node.hostname == homelab  ]
  app:
    image: martadinata666/code-server:latest
    volumes:
      - ./data:/home/debian/code-server
      - /home/dedyms/Documents/docker-gitlab-local:/home/debian/code-server/docker-gitlab
      - ./htdocs:/var/www/html
    ports:
      - 9003:9003
    networks:
      - code-server
    deploy:
      placement:
        constraints: [ node.hostname == homelab  ]
  nginx:
    image: martadinata666/nginx:mainline
    ports:
      - 4000:443
    configs:
      - source: default.conf
        target: /etc/nginx/conf.d/default.conf
    networks:
      - code-server
networks:
  code-server:
    name: code-server
configs:
  default.conf:
    file: ./default.conf

Tag summary

Content type

Image

Digest

sha256:fc840a329

Size

59.5 MB

Last updated

almost 3 years ago

docker pull martadinata666/nginx