首页
学习
活动
专区
圈层
工具
发布
清单首页Docker文章详情

Docker搭建Nginx服务

1.拉取镜像

代码语言:text
复制
docker pull docker.io/nginx

2.docker部署

代码语言:text
复制
docker run -itd \
--name nginx \
--restart always \
-p "80:80" \
-v "/usr/share/nginx:/usr/share/nginx" \
-v "/usr/share/nginx/html:/usr/share/nginx/html" \
-v "/usr/nginx/lib/nginx:/usr/lib/nginx" \
-v "/usr/nginx/default.conf:/etc/nginx/conf.d/default.conf" \
-m "512M" \
docker.io/nginx

3.docker-compose部署

代码语言:yaml
复制
version: '2.0'
services:
    nginx:
        image: docker.io/nginx
        container_name: nginx
        restart: always
        ports:
           - 80:80
        volumes:
           - ./nginx/usr/share/nginx:/usr/share/nginx
           - ./nginx/usr/share/nginx/html:/usr/share/nginx/html
           - ./nginx/lib/nginx:/usr/lib/nginx
           - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
        deploy:
            resources:
              limits:
                cpus: '0.2'
                memory: 512M
              reservations:
                cpus: '0.2'
                memory: 512M
代码语言:text
复制
docker-compose -f nginx.yaml up [-d] 

附件:nginx.conf配置文件

代码语言:text
复制
server {
    listen 80;
    listen  [::]:80;
    server_name  localhost;
    # 项目1
    location /p1 {
        root   /usr/share/nginx/html;
        index  index.html index.htm;        
        try_files $uri $uri/ /p1/index.html;
    }
    # 项目2
    location /p2 {
        root   /usr/share/nginx/html;
        index  index.html index.htm;        
        try_files $uri $uri/ /p2/index.html;
    }
    
    
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {        
        root   /usr/share/nginx/html;    
    }
}

附注:关于nginx转发云上接口

代码语言:text
复制
location / {    
    proxy_pass https://suggest.taobao.com/sug?code=utf-8&q=内裤&callback=cb;
}
下一篇
举报
领券