Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

https://hub.docker.com/_/nginx

Docker-Compose:

Reverse Proxy: network_mode = host

version: '3.7'

services:
 nginxproxy:
    container_name: nginx
    hostname: nginx
    network_mode: host
    image: nginx
    volumes:
      - type: bind
        read_only: true
        source: /opt/nginx/conf/
        target: /etc/nginx
      - type: bind
        read_only: true
        source: /etc/ssl/
        target: /etc/ssl/
      - type: bind
        read_only: true
        source: /etc/letsencrypt/
        target: /etc/letsencrypt/
      - type: bind
        source: /opt/nginx/html/
        target: /var/www/html/
      - type: bind
        source: /opt/nginx/mnt/
        target: /mnt

    environment:
      - 'TZ=America/Whitehorse'

SystemD Integration:

WD=/opt/nginx/setup
cat << EOF >$WD/nginx.service.setup.sh
cat << EOL >/lib/systemd/system/nginx.service
[Unit]
Description=nginx_Docker
Requires=docker.service network-online.target

[Service]

Restart=on-abnormal
ExecStart=/usr/bin/docker-compose --project-name nginx --project-directory $WD -f $WD/docker-compose.yaml up
ExecStop=/usr/bin/docker-compose --project-name nginx --project-directory $WD -f $WD/docker-compose.yaml stop

[Install]
WantedBy=multi-user.target
EOL
systemctl enable nginx
systemctl start nginx
EOF
chmod +x $WD/nginx.service.setup.sh
$WD/nginx.service.setup.sh

Basic WebServer:


WD=/opt/webserver
mkdir -p $WD/{mnt,setup,conf,html}
cd $WD/setup
cat << 'EOF' >docker-compose.yaml
version: '3.7'

services:
 webserverproxy:
    container_name: webserver
    hostname: webserver
    image: nginx
    ports:
    - 8733:80
    volumes:
      - type: bind
        read_only: true
        source: /opt/webserver/html/
        target: /usr/share/nginx/html
    environment:
      - 'TZ=America/Whitehorse'

EOF
chmod +x docker-compose.yaml

WD=/opt/webserver/setup
cat << EOF >$WD/webserver.service.setup.sh
cat << EOL >/lib/systemd/system/webserver.service
[Unit]
Description=webserver_Docker
Requires=docker.service network-online.target

[Service]

Restart=on-abnormal
ExecStart=/usr/bin/docker-compose --project-name webserver --project-directory $WD -f $WD/docker-compose.yaml up
ExecStop=/usr/bin/docker-compose --project-name webserver --project-directory $WD -f $WD/docker-compose.yaml stop

[Install]
WantedBy=multi-user.target
EOL
systemctl enable webserver
systemctl start webserver
EOF
chmod +x $WD/webserver.service.setup.sh
$WD/webserver.service.setup.sh


CLI Access:


echo 'alias nginxcli="docker exec -it nginx /bin/bash"' >> ~/.bashrc
source ~/.bashrc


Add to XYMon:

nano /etc/xymon/analysis.cfg && systemctl restart xymon xymon-client
        PROC NAME




  • No labels