网站首页 > 技术教程 正文
Docker 安装 Nginx
安装基本步骤
1、查找 Nginx 镜像
docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 11117 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1571 [OK] richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 696 [OK] jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as p… 494 [OK] webdevops/php-nginx Nginx with PHP-FPM 123 [OK] zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi… 92 [OK] bitnami/nginx Bitnami nginx Docker Image 64 [OK] linuxserver/nginx An Nginx container, brought to you by LinuxS… 57 1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 49 [OK] zabbix/zabbix-web-nginx-pgsql Zabbix frontend based on Nginx with PostgreS… 30 [OK] tobi312/rpi-nginx NGINX on Raspberry Pi / armhf 24 [OK] nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 17 nginxdemos/hello NGINX webserver that serves a simple page co… 13 [OK] wodby/drupal-nginx Nginx for Drupal container image 12 [OK] schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 12 [OK] blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 12 [OK] centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 10 centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 7 nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 4 1science/nginx Nginx Docker images that include Consul Temp… 4 [OK] mailu/nginx Mailu nginx frontend 3 [OK] travix/nginx NGinx reverse proxy 2 [OK] toccoag/openshift-nginx Nginx reverse proxy for Nice running on same… 1 [OK] ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 0 [OK] wodby/nginx Generic nginx 0 [OK]
2、下载 Nginx 镜像(默认nginx 镜像)
docker pull nginx
Using default tag: latest latest: Pulling from library/nginx f7e2b70d04ae: Pull complete 08dd01e3f3ac: Pull complete d9ef3a1eb792: Pull complete Digest: sha256:98efe605f61725fd817ea69521b0eeb32bef007af0e3d0aeb6258c6e6fe7fc1a Status: Downloaded newer image for nginx:latest
3、查看本地的 Nginx 镜像
docker images nginx
REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 881bd08c0b08 2 weeks ago 109MB
Docker 运行 Nginx
先要把 nginx 的文件目录,映射到我们服务器目录
1、创建目录
mkdir -p ~/nginx/www ~/nginx/logs ~/nginx/conf
2、在服务器路径[/root/nginx/conf]下配置nginx.conf
vi /root/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
access_log logs/access.log ;
sendfile on;
server {
listen 80;
server_name localhost;
location / {
root www;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
3、在服务器路径[/root/nginx/www]编译index.html页面
vi /root/nginx/www/index.html
<!DOCTYPE html>
<html>
<head>
<title> Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1> Welcome to nginx!</h1>
</body>
</html>
4、运行 nginx
docker run -p 80:80 --name mynginx -v /root/nginx/www:/etc/nginx/www -v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /root/nginx/logs:/var/log/nginx -d nginx
a6113e26b00feb8ca084c919316c61da59fad5300b3b5bac5895d09ee86944f2
Docker run 命令的参数说明
- p 80:80:将容器的80端口映射到主机的80端口
- --name mynginx:将容器命名为mynginx
- -v /root/nginx/www:/etc/nginx/www :将主机中当前目录下的www挂载到容器的/etc/nginx/www
- -v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:将主机中当前目录下的nginx.conf挂载到容器的/etc/nginx/nginx.conf
- -v /root/nginx/logs:/var/log/nginx:将主机中当前目录下的logs挂载到容器的/var/log/nginx
5、直接浏览器访问:我的地址:url
6、查看日志
more /root/nginx/logs/access.log
192.168.199.1 - - [25/Mar/2019:15:32:51 +0000] "GET /index.html HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" 192.168.199.1 - - [25/Mar/2019:15:34:28 +0000] "GET /index.html HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" 192.168.199.1 - - [25/Mar/2019:15:34:29 +0000] "GET /index.html HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
7、扩展进入安装的nginx 容器
sudo docker exec -it mynginx /bin/bash
希望我的分享可以帮助到你,如果你在内容技术上遇到难题,可以+关注■@主引教程 ,反馈给我们。我们会及时回复,如果有那些内容有误可以直接提出来,我们会及时纠正,谢谢来访。
猜你喜欢
- 2024-09-16 Windows下的LAMP开发环境Winginx介绍
- 2024-09-16 测试架构师必备技能-Nginx安装部署实战
- 2024-09-16 Docker部署 Tomcat集群、 Nginx负载均衡
- 2024-09-16 浅谈Nginx服务器的内部核心架构设计
- 2024-09-16 Django项目部署到服务器(django项目部署到服务器 windows)
- 2024-09-16 在.net core中使用nginx做负载均衡
- 2024-09-16 如何使用windows版Docker(dockerwindows下安装使用)
- 2024-09-16 Nginx为同主机配置Https多域名(nginx配置https需要两个证书吗)
- 2024-09-16 前后端都用得上的 Nginx 日常使用经验
- 2024-09-16 centos7.9 nginx1.24.0下载安装配置
欢迎 你 发表评论:
- 12-13电脑上不了网无internet访问
- 12-13怎么下载winrar解压缩软件(.rar怎么下载)
- 12-13设置路由器tplink(设置路由器怎么设置教程)
- 12-13360浏览器官网在线使用
- 12-13一键系统备份工具(一键系统备份软件)
- 12-132345浏览器影视大全(2345浏览器版本大全)
- 12-13office产品密钥在哪看(查看office产品密钥)
- 12-13电脑速度慢怎么清理(电脑很慢如何清理)
- 最近发表
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)

本文暂时没有评论,来添加一个吧(●'◡'●)