Skip to content

Instantly share code, notes, and snippets.

@devils-ey3
Created December 8, 2018 23:49
Show Gist options
  • Save devils-ey3/18a8b589e237706315b2fd1db37f3949 to your computer and use it in GitHub Desktop.
Save devils-ey3/18a8b589e237706315b2fd1db37f3949 to your computer and use it in GitHub Desktop.
server {
listen 80 default_server;
listen [::]:80 default_server;
root /opt/projects;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
FROM ubuntu:16.04
RUN apt-get update
RUN wget https://nginx.org/download/nginx-1.14.0.tar.gz
RUN tar zxf nginx-1.14.0.tar.gz
RUN cd nginx-1.14.0
RUN ./configure && cd ~
RUN apt-get install -y nginx php7.0-fpm supervisor && \
rm -rf /var/lib/apt/lists/*
ENV nginx_vhost /etc/nginx/sites-available/default
ENV php_conf /etc/php/7.0/fpm/php.ini
ENV nginx_conf /etc/nginx/nginx.conf
ENV supervisor_conf /etc/supervisor/supervisord.conf
COPY default ${nginx_vhost}
RUN sed -i -e 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' ${php_conf} && \
echo "\ndaemon off;" >> ${nginx_conf}
COPY supervisord.conf ${supervisor_conf}
RUN mkdir /opt/projects
RUN mkdir -p /run/php && \
chown -R www-data:www-data /opt/projects && \
chown -R www-data:www-data /run/php
# Volume configuration
VOLUME ["/etc/nginx/sites-enabled", "/etc/nginx/certs", "/etc/nginx/conf.d", "/var/log/nginx", "/opt/projects"]
# Configure Services and Port
COPY start.sh /start.sh
CMD ["./start.sh"]
EXPOSE 80 443
For install docker into ubuntu based os
$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
$ sudo touch /etc/apt/sources.list.d/docker.list && sudo nano /etc/apt/sources.list.d/docker.list
and append this repo 'deb https://apt.dockerproject.org/repo ubuntu-xenial main'
$sudo apt-get update
if any warning of `signature verfication error'
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $(Signature key)
$ sudo usermod -aG docker $USER # for add current user into docker group for sudo permission
========================================
for install image
$ mkdir ubuntuimage && cd ubuntuimage
download `default`, `supervisord.conf`, `Dockerfile`, `start.sh` into corrent directory
give execute permission to start.sh
$ chmod +x start.sh
$ sudo docker build -t nginx_image .
then make a directory where it represent /opt/projects
$ sudo mkdir -p /webroot
$ sudo touch /webroot/info.php
write `<?php phpinfo(); ?>` into /webroot/info.php
$ sudo docker run -d -v /webroot:/opt/projects -p 8080:8080 --name devops nginx_image # here devops is the container name
Now it run into 8080 port
/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
[unix_http_server]
file=/dev/shm/supervisor.sock ; (the path to the socket file)
[supervisord]
logfile=/var/log/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
user=root ;
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///dev/shm/supervisor.sock ; use a unix:// URL for a unix socket
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
[include]
files = /etc/supervisor/conf.d/*.conf
[program:php-fpm7.0]
command=/usr/sbin/php-fpm7.0 -F
numprocs=1
autostart=true
autorestart=true
[program:nginx]
command=/usr/sbin/nginx
numprocs=1
autostart=true
autorestart=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment