nginx 路径查找:
1、linux 查看nginx安装目录
在shell中输入命令
ps -ef | grep nginx
返回结果
root 4593 1 0 Jan23 ? 00:00:00 nginx: master process /usr/sbin/nginx
2、查看nginx.conf配置文件目录
在shell中输入命令
nginx -t
返回结果
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
3、启动nginx服务
输入命令
nginx安装目录 -c nginx.conf配置文件目录
其中:参数 “-c” 指定了配置文件的路径,如果不加 “-c” 参数,Nginx 会默认加载其安装目录的 conf 子目录中的 nginx.conf 文件。
开始制作
1、 拉取镜像
docker pull nginx
创建目录
创建一个目录用来存放文件,方便我们进行修改
mkdir -p /everything/nginx/conf /everything/nginx/html
创建配置文件
在我们创建的目录下创建一个配置文件
touch /everything/nginx/conf/nginx.conf
修改配置文件
把我们创建的目录下的 nginx.conf 修改为以下内容
#工作进程数 1 ,不要超过计算机的核数,四核配置4,八核配置8 worker_processes 1;
#工作连接数,也就是线程,一个进程有1024个线程, events { worker_connections 1024; }
#http请求配置 http { default_type application/octet-stream;
#sendfile为发送文件,要on开启
sendfile on;
#keepalive_timeout超时时间
keepalive_timeout 65;
server {
#监听的端口,这里为80
listen 80;
#server_name就是域名,
server_name localhost;
#location域名代理地址
# / 代表所有请求路径
location / {
root /usr/share/nginx/html;
index index.html;
}
}
}
创建html
创建在 /everything/nginx/html目录下创建index.html
touch /everything/nginx/index.html
index.html内容为
我是index.html…
启动容器
docker run --name nginx01 -p 80:80 -v /everything/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /everything/nginx/html:/usr/share/nginx/html --restart always -d nginx
访问 127.0.0.1