阿里云搭建nginx,基于docker-compose

mkdir /opt/nginx

#编辑docker-compose.yml文件
vim docker-compose.yml

version: '3.1'
services:
  nginx:
    restart: always
    image: daocloud.io/library/nginx:latest
    container_name: nginx
    ports:
      - 80:80
    volumes:
      - /opt/nginx/nginx.conf:/etc/nginx/nginx.conf
      - /opt/nginx/html:/usr/share/nginx/html
      - /opt/nginx/log:/var/log/nginx
#编辑 nginx.conf
vim nginx.conf
user  root;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

# 以上统称为全局块
# worker_processes数值越大,Nginx的并发能力就越强
# error_log表示Nginx的错误日志存放位置

events {
    worker_connections  1024;
}
# events模块
# worker_connections数值越大,Nginx的并发能力就越强

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;


    #  conf.d下default.conf的内容,一个server块

    server {
        listen       80;
        listen  [::]:80;
        server_name  localhost;

        location / {
            root   /usr/share/nginx/html;
            index  h1.html h1.htm;
        }
                # location块
                # root:将接收到的请求根据/usr/share/nginx/html去查找静态资源
                # index:默认去上述路径中找到index.html或index.htm
    }
        # server块
        # listen: 代表Nginx监听的端口号
        # localhost: 代表Nginx接收请求的ip


    include /opt/nginx/conf.d/*.conf;
}
# http块
# include表示引入一个外部的文件 --> /mime.types中存放着大量的媒体类型
# include /etc/nginx/conf.d/*.conf; --> 引入了conf.d目录下的以.conf为结尾的配置文件
~                                                                                    
#几个注意点
# 1。 user root 必须与你的用户名对应
# 2.nginx.conf中路径是以nginx容器的路径来写的,并不是宿主机路径

#编写html
vim /opt/nginx/html/h1.html
<h1>!!!!hi nginx !!!</h1>


~                                       
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值