Nginx学习

1-什么是Nginx

        Nginx 是⼀款⾼能的 C/反向代理服务器及电⼦邮件(IMAP/POP3)代理服务器

2-应用场景

  • http 服务器。Nginx 是⼀个 http 服务可以独⽴提供 http 服务。可以做⽹⻚静态服务器。
  • 虚拟主机。可以实现在⼀台服务器虚拟出多个⽹站。例如个⼈⽹站使⽤的虚拟主机。
  • 反向代理,负载均衡。当⽹站的访问量达到⼀定程度后,单台服务器不能满⾜⽤户的请求时,需要⽤ 多台服务器集群可以使⽤ nginx 做反向代理。并且多台服务器可以平均分担负载,不会因为某台服务器 负载⾼宕机⽽某台服务器闲置的情况。

3-Nginx安装

#1. 搜索nginx镜像
    docker search nginx

#2. 拉取nginx镜像
    docker pull nginx

#3. 创建容器,设置端⼝映射、⽬录映射
# 在/root⽬录下创建nginx⽬录⽤于存储nginx数据信息
    mkdir ~/nginx
    cd ~/nginx
    mkdir conf
    cd conf
# 在~/nginx/conf/下创建nginx.conf⽂件
    vim nginx.conf
#编写以下内容
    user nginx;
    worker_processes 1;
    error_log /var/log/nginx/error.log warn;
    pid /var/run/nginx.pid;
    events {
         worker_connections 1024;
    }
    http {
         include /etc/nginx/mime.types;
         default_type application/octet-stream;
         log_format main '$remote_addr - $remote_user [$time_local] "$request" '
         '$status $body_bytes_sent "$http_referer" '
         '"$http_user_agent" "$http_x_forwarded_for"';
         access_log /var/log/nginx/access.log main;
         sendfile on;
         #tcp_nopush on;
         keepalive_timeout 65;
         #gzip on;
         include /etc/nginx/conf.d/*.conf;
    }

#4.挂载到容器  在~/nginx目录下
    docker run -id --name=c_nginx \
    #将容器的 80端⼝映射到宿主机的 80 端⼝
    -p 80:80 \
    -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
    -v $PWD/conf.d:/etc/nginx/conf.d \
    -v $PWD/logs:/var/log/nginx \
    -v $PWD/html:/usr/share/nginx/html \
    nginx

#5.配置 ~/nginx/conf.d/80.conf
    server {
         listen 80; # 监听的端⼝
         server_name localhost; # 域名或ip
         location / { # 访问路径配置
             root /usr/share/nginx/html;# 根⽬录
             index index.html index.htm; # 默认⾸⻚
         }
         error_page 500 502 503 504 /50x.html; # 错误⻚⾯
         location = /50x.html {
             root html;
         }
    }

#6.浏览器访问nginx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

潘875

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值