Nginx

宿主机安装

建议安装在宿主机,反向代理时,使用127.0.0.1映射docker应用容器的端口

(docker安装的话,外网->nginx 容器 ->宿主机->  应用的容器,会有更多的网络损耗)

#宿主机上安装 nginx
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx -y

#版本:nginx -v
#目录:/etc/nginx
#配置:/etc/nginx/conf.d/default.conf

#启动
sudo systemctl start nginx.service
#开机自动启动
sudo systemctl enable nginx.service 

 Docker 安装 

# -d 后台运行   -p 端口映射   -v 挂在数据卷   --restart=always 自动启动
docker run --name nginx -d -p 80:80 --restart=always -v /data/nginx/conf.d:/etc/nginx/conf.d -v /data/nginx/html:/usr/share/nginx/html nginx:latest

  

配置 

cd /data/nginx/conf.d
vim default.conf
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

  

默认首页

cd /data/nginx/html

vim index.html

  

#配置成功后,可以将容器commit为一个新的image
#-a :提交的镜像作者;  -c :使用Dockerfile指令来创建镜像;-m :提交时的说明文字; -p :在commit时,将容器暂停。
docker commit -a "fmp" -m "mynginx" a404c6c174a2 mynginx:v1

  

  nginx配置参考:https://www.cnblogs.com/lich1x/p/11225528.html

posted @ 2019-09-08 14:43  码农搞事情  阅读(214)  评论(0编辑  收藏  举报