一、环境信息
- 操作系统:centos7.3
- docker版本:Docker version 1.13.1, build 07f3374/1.13
- nginx镜像:docker.io/nginx
二、安装步骤
1、新建目录
mkdir /usr/local/src/nginx #nginx根目录
mkdir /usr/local/src/nginx/cert #存放nginx证书的目录
mkdir /usr/local/src/nginx/conf #存放nginx配置文件的目录
mkdir /usr/local/src/nginx/logs #存放nginx日志文件的目录
mkdir /usr/local/src/nginx/www #存放静态网页文件的目录
效果如图所示:
2、目录授权
chmod -R 755 /usr/local/src/nginx
3、创建配置文件
在/usr/local/src/nginx/conf目录下面创建nginx.conf文件,确保该文件的读写写执行权限,
切记在nginx.conf配置的映射静态资源的路径应该是原来容器的路径,只不过是这里将其映射出到了宿主机器来方便操作了!!!
文件大体内容如下:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
client_max_body_size 30m;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
4、创建容器
docker run -d -p 80:80 \
--name nginx \
-p 443:443 --privileged=true \
-v /usr/local/src/nginx/cert:/etc/nginx/cert \
-v /usr/local/src/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /usr/local/src/nginx/www:/usr/share/nginx/html \
-v /usr/local/src/nginx/logs:/var/log/nginx nginx:latest
执行完效果如图所示:
5、查看容器创建是否成功
6、测试页面
在/usr/local/src/nginx/www目录下新建一个index.html测试页面,内容随意,我就直接拿nginx的页面大体如下:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
7、测试
浏览器输入http://192.168.1.127/地址,看到如下效果恭喜你成功了
由于使用优快云代码框有问题,故我的代码就直接写了,裸奔于富文本框,大家将就着看吧。
TKS!