Docker容器编译安装Nginx
阅读原文时间:2023年07月08日阅读:2

Docker容器编译安装Nginx,最简单的Nginx配置。

创建容器&进入容器

  • 宿主机2080映射容器的80端口

    [root@localhost ~]# docker run -i -d -h centoscs --name centoscs --net docker-br0 --ip 172.127.0.201 -p 2080:80 -v /Tools:/Tools --privileged=true centos:7 /usr/sbin/init
    [root@localhost ~]# docker exec -it centoscs /bin/bash

    [root@localhost /]# yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel

    [root@localhost /]# mkdir Tools
    [root@localhost /]# cd Tools
    [root@localhost Tools]# wget http://nginx.org/download/nginx-1.18.0.tar.gz

    [root@localhost Tools]# tar -zxvf nginx-1.18.0.tar.gz

    [root@localhost Tools]# cd nginx-1.18.0

  • --prefix 指定安装路径

    [root@centoscs nginx-1.18.0]# ./configure --prefix=/usr/local/nginx
    [root@centoscs nginx-1.18.0]# make && make install

  • 配置文件路径 /usr/local/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 / {
    # proxy_pass http://localhost:8080; # 代理的服务地址
    index index.html index.htm index.jsp;
    root html;
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }
    }
    }

  • 启动服务路径 /usr/local/nginx/sbin

    [root@centoscs sbin]# ./nginx #启动
    [root@centoscs sbin]# ./nginx -s reload # 重启
    [root@centoscs sbin]# ./nginx -s stop # 停止
    [root@centoscs sbin]# ./nginx -v # 查看版本

  • 未代理任何服务

  • 配置了代理tomcat服务