Skip to content

Commit

Permalink
Merge pull request #8 from voocel/v2
Browse files Browse the repository at this point in the history
init v2
  • Loading branch information
voocel authored May 10, 2019
2 parents fbf4f73 + 42c7d1b commit bcbe594
Show file tree
Hide file tree
Showing 44 changed files with 454 additions and 3,514 deletions.
66 changes: 24 additions & 42 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,40 @@
version: '2'
# 定义四个服务nginx,php,mysql,redis
version: '3'
services:
nginx:
# 依赖php服务,意味着在启动nginx之前先启动php
build: ./nginx
depends_on:
- php
# nginx镜像的路径
#build: ./nginx
image: yahuiwong/lnmp:nginx1.13.0
# 这样使nginx容器把网站文件和目录存放到主机目录中,持久化和方便管理
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/www:/usr/share/nginx/html
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/ssl/:/etc/nginx/ssl/
- ./nginx/cert:/etc/nginx/cert
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/log/error.log:/var/log/nginx/error.log
# nginx意外退出时自动重启
restart: always

# 映射80和443端口
ports:
- "80:80"
- "443:443"
networks:
- frontend

# 容器名称
restart: always
container_name: nginx

php:
depends_on:
- mysql
- redis
#build: ./php
image: yahuiwong/lnmp:php7.1.5
ports:
- "9000"
build: ./php
volumes:
- ./nginx/www:/var/www/html
- ./php/config/php.ini:/usr/local/etc/php/php.ini
- ./php/config/php-fpm.conf:usr/local/etc/php-fpm.conf
- ./php/config/php-fpm.d:/usr/local/etc/php-fpm.d
networks:
- frontend
- backend
volumes:
- ./php/php-fpm.conf:/usr/local/php/etc/php-fpm.conf
- ./php/www.conf:/usr/local/php/etc/php-fpm.d/www.conf
- ./php/php.ini:/usr/local/php/etc/php.ini
- ./php/log/php-fpm.log:/usr/local/php/var/log/php-fpm.log
- ./nginx/www:/usr/share/nginx/html
- backend
restart: always
container_name: php

# MySQL
mysql:
image: hub.c.163.com/library/mysql:latest
build: ./mysql
ports:
- "127.0.0.1:3306:3306"
- "3306:3306"
volumes:
- ./mysql/data:/var/lib/mysql
- ./mysql/my.cnf:/etc/my.cnf
Expand All @@ -63,20 +45,20 @@ services:
restart: always
container_name: mysql

# REDIS
redis:
#build: ./redis
image: yahuiwong/lnmp:redis3.2.9
build: ./redis
ports:
- "127.0.0.1:6379:6379"
networks:
- backend
- "6379:6379"
volumes:
- ./redis/redis.conf:/usr/local/redis/redis.conf
- ./redis/redis.conf/:/usr/local/etc/redis.conf
- ./redis/data:/usr/local/redis/data
- ./redis/redis.log:/usr/local/redis/redis.log
networks:
- backend
restart: always
container_name: redis

networks:
frontend:
backend:

File renamed without changes.
2 changes: 1 addition & 1 deletion mysql/my.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ character-set-server=utf8

collation-server=utf8_general_ci

skip-name-resolve

[mysqld_safe]
log-error=/var/log/mysqld.log
Expand All @@ -39,4 +40,3 @@ pid-file=/var/run/mysqld/mysqld.pid
[client]

default-character-set=utf8

79 changes: 4 additions & 75 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,77 +1,6 @@
# 拉取 CentOS
FROM hub.c.163.com/library/centos:latest
FROM daocloud.io/library/nginx:1.13.0-alpine

# 维护者
MAINTAINER voocel <voocel@gmail.com>
### set timezome
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 设置 openssl 和 nginx 版本
ENV NGINX_VERSION 1.13.0

# 安装依赖
RUN set -x \
&& yum update -y \
&& yum install -y wget gcc gcc-c++ make automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel perl file tar bzip2-devel bzip2 openssl openssl-devel zlib zlib-devel \

# 创建下载目录
&& mkdir ~/download \

# 下载 openssl
&& cd ~/download \

# 下载 nginx
&& wget http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz \
&& tar -zxvf nginx-$NGINX_VERSION.tar.gz \
&& cd nginx-$NGINX_VERSION \
&& mkdir -p /var/cache/nginx \
&& groupadd nginx \
&& useradd -r -g nginx nginx \
&& ./configure \
--prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--sbin-path=/usr/sbin/nginx \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module \
&& make \
&& make install \
&& rm -rf ~/download \
&& yum clean all

# 若要使用https,请将以下三个注释去掉,并在ssl文件夹中添加你自己申请的两个证书文件
# && mkdir -p /etc/nginx/cert
#COPY ssl/nginx.pem /etc/nginx/cert/nginx.pem
#COPY ssl/nginx.key /etc/nginx/cert/nginx.key

CMD ["/usr/sbin/nginx","-g","daemon off;"]

EXPOSE 80 443
File renamed without changes.
74 changes: 71 additions & 3 deletions nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
server {
server {
listen 80;
server_name localhost;
# 全站使用https则开启下面这个注释
Expand Down Expand Up @@ -30,8 +30,8 @@

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {

location ~ \.php$ {
root /var/www/html;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Expand All @@ -45,3 +45,71 @@
# deny all;
#}
}

server {
listen 443 ssl;
server_name localhost;
#valid_referers none blocked server_names
# https://segmentfault.com;
#if ($invalid_referer) {
# return 403;
#}

#禁止使用ip直接访问
#if ( $host ~* "\d+\.\d+\.\d+\.\d+" ) {
# return 501;
# }

ssl_certificate /etc/nginx/cert/*.pem;
ssl_certificate_key /etc/nginx/cert/*.key;

ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;

ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

root /usr/share/nginx/html;

#location ~* ^.+\.(ico|gif|jpg|jpeg|png)$ {
# access_log off;
# expires 30d;
#}
#location ~* ^.+\.(css|js|txt|xml|swf|wav)$ {
# access_log off;
# expires 24h;
#}
#location ~* ^.+\.(html|htm)$ {
# expires 1h;
#}

#location ~* ^.+\.(eot|ttf|otf|woff|svg)$ {
# access_log off;
# expires max;
#}

location / {
#valid_referers https://segmentfault.com;
#if ($invalid_referer) {
# return 502;
#}
#try_files $uri $uri/ /index.php?$query_string;

index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}


}

location ~ \.php$ {
root /var/www/html;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

}
21 changes: 0 additions & 21 deletions nginx/conf.d/frps.proxy.conf

This file was deleted.

Loading

0 comments on commit bcbe594

Please sign in to comment.