linux怎么查看本机内存大小
229
2022-10-09
#yyds干货盘点# Nginx学习笔记1(介绍与安装)
1、为什么要学习Nginx
问题1:客户端到底要将请求发送给哪台服务器问题2:如果所有客户端的请求都发送给了服务器1问题3:客户端发送的请求可能是申请动态资源的,也有申请静态资源的
2、Nginx的特点
Nginx的特点1.稳定性极强,7*24小时不间断运行(就是一直运行)2.Nginx提供了非常丰富的配置实例3.占用内存小,并发能力强(随便配置一下就是5w+,而tomcat的默认线程池是150)
3、Nginx的安装
1、使用docker-compose安装#在/opt目录下创建docker_nginx目录cd /optmkdir docker_nginx#创建docker-compose.yml文件并编写下面的内容,保存退出
写入以下内容 :
version: '3.1' services: nginx: restart: always image: daocloud.io/library/nginx:latest container_name: nginx ports: - 80:80
4、nginx的配置文件
关于nginx.conf的核心配置文件
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; # 以上同城为全局块 # worker_processes的数值越大,Nginx的并发能力就越强 # error_log代表Nginx错误日志存放的位置 # pid是Nginx运行的一个标识 events { worker_connections 1024; } # events块 # worker_connections的数值越大,Nginx的并发能力就越强 { 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_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; # 这个主要是引入下面的server块的也就是下面,default.conf文件中的 server中的。 # 当然其他文件也是需要的。 } # http块 # include代表引入一个外部文件 # include /etc/nginx/mime.types; mime.types中存放着大量媒体类型 #include /etc/nginx/conf.d/*.conf; 引入了conf.d下以.conf为结尾的配置文件
关于nginx的 conf.d目录下的default.conf文件,内容如下:
server {listen 80;listen [::]:80;server_name localhost;
# server块 # listen代表Nginx监听的端口号 # server_name代表Nginx接受请求的IP #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } # 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; #}
}
4.3修改创建nginx容器用的 docker-compose 文件,方便修改容器内的配置文件
#退出容器exit#关闭容器docker-compose down#修改docker-compose.yml文件如下
version: '3.1' services: nginx: restart: always image: daocloud.io/library/nginx:latest container_name: nginx ports: - 80:80 volumes: - /opt/docker_nginx/conf.d/:/etc/nginx/conf.d # 配置映射 这样就可以不必去容器内容部修改文件了
#重新构建容器docker-compose bulid#重新启动容器docker-compose up -d
这时我们再次访问80端口是访问不到的,因为我们映射了数据卷之后还没有编写server块中的内容
我们在/opt/docker_nginx/conf.d下新建default.conf,并插入如下内容
server { listen 80; listen [::]:80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } }
这样我们只需要在服务器对应的路径下建立配置文件,就可以映射都容器内部了,
重启nginx : 在nginx的sbin目录下 执行 ./nginx -s reload 、
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~