0
点赞
收藏
分享

微信扫一扫

Nginx简介

small_Sun 2022-05-01 阅读 74

什么是Nginx

Nginx 是⼀款⾼性能的 http 服务器/反向代理服务器及电⼦邮件(IMAP/POP3)代理服务器。由俄罗斯的程序设计师伊⼽尔·⻄索夫(Igor Sysoev)所开发,官⽅测试 nginx 能够⽀⽀撑 5 万并发链接,并且cpu、内存等资源消耗却⾮常低,运⾏⾮常稳定。

Nginx应用场景

docker下安装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;
}

~/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;
}
}
docker run -id --name=c_nginx \
-p 80:80 \
-p 81:81 \
-p 82:82 \
-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

4. 使⽤外部机器访问nginx

举报

相关推荐

0 条评论