网站响应方案,北京工程建设,wordpress 博客系统,网站建设课程设计心得体会Nginx 网站服务 是一个高性能 轻量级web服务软件#xff0c; 高新能#xff1a;对http并发连接的处理能很高#xff0c;单台处理器可支持30000-50000个并发请求#xff0c;#xff08;一般设置在20000个左右#xff09;
轻量级#xff1a;nginx软件很小#xff0c;安装…Nginx 网站服务 是一个高性能 轻量级web服务软件 高新能对http并发连接的处理能很高单台处理器可支持30000-50000个并发请求一般设置在20000个左右
轻量级nginx软件很小安装所需的空间很小 稳定性强:对系统资源消耗低
Nginx 的主要功能
1处理静态网页html htm 图像
2 支持反向代理实现负载均衡负载均衡靠算法实现
3 处理动内容的能力
4 一个nginx可以配置多个虚拟主机每一个虚拟主机可以作为一个域名的站点拥有独立的配置和资源
5 URL重定向可以对URL 的请求进行修改和重定向
6 缓存机制可以缓存静态文件的额动态内容
7 包含日志记录服务日志访问日志报错日子 控制日志还是在/var/log/messsages
8 代理服务器通过代理可以访问其他的后端服务器
2 Nginx 下面的文件 conf : 保存nginx的所有配置文件 其中nginx.conf是nginx的配置文件 html: 保存nginx的web 文件 .html为结尾的文件图片 logs: 保存日志的日录路径可以改 Sbin nginx 的二进制启动文件 html下面的 50x.html是nginx默认的报错提示页面 access.log 记录的是访问日志记录 error.log 记录的是报错日志 nginx-t 检测nginx配置文件以及配置文件的语法是否正确 被http占用 nginx -v 只是查看nginx的版本 nginx -V 查看版本 和nginx支持的配置模块 nginx -s stop restart reload 给nginx主程序发送信息不能开启nginx服务 如何安装nginx 1、systemctl stop firewalld systemctl disable firewalld setenforce 0 2、安装依赖包 yum -y install gcc pcre-devel openssl-devel zlib-devel openssl openssl-devel 3、创建运行用户、组 Nginx 服务程序默认以 nobody 身份运行建议为其创建专门的用户账号以便更准确地控制其访问权限 useradd -M -s /sbin/nologin nginx 4、编译安装Nginx cd /opt tar zxvf nginx-1.22.0.tar.gz -C /opt/ cd nginx-1.22.0/ ./configure --prefix/usr/local/nginx \ --usernginx \ --groupnginx \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-pcre \ --with-stream \ --with-stream_ssl_module \ --with-stream_realip_module 5、make make install 6、chown -R nginx.nginx /usr/local/nginx #修改权限 7、ln -s /usr/local/nginx/sbin/nginx /usr/sbin/ #让系统识别nginx的操作命令 8、vim /lib/systemd/system/nginx.service [Unit] Descriptionnginx - high performance web server Documentationhttp://nginx.org/en/docs/ Afternetwork-online.target remote-fs.target nss-lookup.target Wantsnetwork-online.target [Service] Typeforking PIDFile/usr/local/nginx/run/nginx.pid #注意文件位置如果不对 启动不了 ExecStart/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf #注意启动文件位置 ExecReload/bin/kill -s HUP $MAINPID #相当于重启 ExecStop/bin/kill -s TERM $MAINPID #相当于stop [Install] WantedBymulti-user.target #支持多用户模式 9、mkdir -p /usr/local/nginx/run/ #创建目录 10、vim /usr/local/nginx/conf/nginx.conf #修改配置文件 pid /usr/local/nginx/run/nginx.pid; #找到 pid的位置修改 11、systemctl daemon-reload #重新加载配置 12、systemctl start nginx.service 配置文件 user nobody; 运行用户默认使用nginx。 worker_processes 1; 工作进程数量根据服务器的CPU数来填写或根据访问量来选择硬件条件满足的情况下。 pid /usr/local/nginx/run/nginx.pid; PID文件的完整。 events { worker_connections 1024; } nginx服务端可以同时并发的连接数最多只有1024个。 http { include 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 logs/access.log main; sendfile on; 支持文件的下载功能。 #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; 连接保持时间65。 #gzip on; 开启页面的压缩功能。 server { listen 80; 虚拟主机的监听端口多个虚拟主机端口的区分。 server_name localhost; 站点的域名 #charset koi8-r; charset utf-8 配置字符的默认编码支持中文 #access_log logs/host.access.log main; location /liu { 匹配URI的路径也是名称 / 配置的家目录下 root /opt; 匹配的是安装路径当中位置 html alias /opt/liu; alias 加全部路径 不能与上面的拼接 index index.html index.htm; 都是index开头而且.html .htm Vim nginx.conf 只能修改了系统配置文件(Vim /etc/security/limits.conf #限制系统打开的配置文件 ) 才能限制连接数 注意设置保存后需要重新ssh连接才会看到配置更改的变化 vim /etc/security/limits.conf #最大进程数的软限制 65535 #最大进程数的硬限制65535 #打开文件的限制最大65535 修改之后只能重启 Iptables 修改内核文件 用sysctl -p 直接生效 但是这里的limits.conf 必须要重启reboot 这3个都是全局的配置文件 vim nginx.conf vim nginx,conf http块代理缓存日志虚拟主机的第三方模块 Nginx的功能模块 proxy代理功能 核心的模块之一配置反向代理的功能 proxy_passz指定 定义在locationg中根据location来的 headers功能模块 处理请求和头部的响应信息获取客户端的真实ip upstream模块 七层方向代理模块只能配置在http模块中或者stream模块中这里配置 Stream :四层反向代理模块只能写在全局配置当中 只能写在http模块上面 或者最下面