安装DOCKER
1. 安装Docker的依赖库。
yum install -y yum-utils device-mapper-persistent-data lvm2
2. 添加Docker CE的软件源信息。
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3. 安装Docker CE。
yum makecache fast
yum -y install docker-ce
4. 启动Docker服务。
systemctl start docker
镜像
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://591l4ieq.mirror.aliyuncs.com"]
}
EOF
1. 重新加载服务配置文件
systemctl daemon-reload
2. 重启Docker服务
systemctl restart docker
安装nginx(法一)
docker pull nginx
docker run --name nginx --restart=always -d -p 80:80 nginx:latest
创建挂载目录
mkdir -p /usr/local/nginx/{conf,log,html}
docker cp nginx:/etc/nginx/nginx.conf /usr/local/nginx/conf/nginx.conf
docker cp nginx:/etc/nginx/conf.d /usr/local/nginx/conf/conf.d
docker cp nginx:/usr/share/nginx/html /usr/local/nginx/
停止并删除容器
docker stop
docker rm
地址映射
'''地址'''
/usr/local/nginx/conf/conf.d/default.conf
'''操作'''
location /files {
alias ../achong;
}
重新挂载
docker run --name nginx --restart=always -d -p 80:80 \
-v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /usr/local/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /usr/local/nginx/log:/var/log/nginx \
-v /usr/local/nginx/html:/usr/share/nginx/html \
--privileged=true nginx
遇到的挂载后还是无法访问的问题,在另一篇文章中解决了
安装nginx(法二,实测可行)
// 安装环境
yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel
上传nginx,解压
进入解压出的文件夹
// 需要https服务
./configure --with-http_ssl_module
// 编译安装nginx
make
make install
进入新的nginx目录(我的是/usr/local/nginx)
//sbin目录下执行
// 开启nginx
./nginx
// 重启nginx
./nginx -s reload
修改nginx.conf文件(我的在/usr/local/nginx/conf)
files暴露路径
achong映射地址
files和achong不要同名
location /files {
alias /achong;
}
示例
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /files {
alias /achong;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
SSL的nginx.conf配置
在conf同目录下创建cert文件夹存放pem和key即证书
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /files {
alias /achong;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
server {
listen 443 ssl;
server_name alijeon;
ssl_certificate cert/950341658467_www.aliyun.com.pem;
ssl_certificate_key cert/956464654817_www.aliyun.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location /files {
alias /achong;
}
}
}