社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
官网:https://nginx.org/en/download.html
Nginx是一个高性能的HTTP
和反向web服务器
,同时也提供了IMAP/POP3/SMTP
服务。
下载官网:https://nginx.org/
特点:占有内存少,并发能力强,事实上;
同类网站:百度、京东、新浪、网易、腾讯、淘宝等。
其Bug非常少,特别容易启动,几乎可以做到7*24不间断服务,即使运行数个月也不需要重新启动,还能不间断服务的情况下进行软件版本的升级。
Nginx代码完全用C语言从头写成。官方数据测试表明能够支持高达50,000个并发链接数的响应。
1 反向代理
2 轮询问
Nginx提供的负载均衡策略有2种,内置策略和扩展策略,内置策略为轮询,加权轮询,Ip hash、扩展策略。
3 动静分离
在软件开发中,有些请求是要后台处理的,有些请求是不需要经过后台处理的(如:css、html、jpg、js等文件),这些不需要经过后台处理的文件成为静态文件。让动态网站里面的动态网页根据一定的规则把不变的资源和经常变得资源区分开来,动静资源做好了拆分之后,我们就可以根据静态资源的特点将其做缓存操作,提高资源响应的速度。
# 先安装gcc-c++编译器
yum install gcc-c++
yum install -y openssl openssl-devel
# 再安装pcre包
yum install -y pcre pcre-devel
# 再安装zlib包
yum install -y zlib zlib-devel
下载
wget http://nginx.org/download/nginx-1.20.2.tar.gz
tar -zxvf nginx-1.20.2.tar.gz
cd nginx-1.20.2
配置环境变量
# NGINX_HOME
export NGINX_HOME=/usr/local/nginx/nginx_install
使用nginx默认配置
./configure --prefix=$NGINX_HOME --with-http_stub_status_module --with-http_ssl_module
编译安装
make && make install
1、启动
$NGINX_HOME/sbin/nginx
2、停止
$NGINX_HOME/sbin/nginx -s stop
3、安全退出
$NGINX_HOME/sbin/nginx -s quit
4、重载配置
$NGINX_HOME/sbin/nginx -s reload
5、查看nginx进程
ps aux | grep nginx
vim conf/nginx.conf
server {
listen 80;
server_name www.***.net;
return 301 https://$http_host$request_uri;
}
rewrite ^/(.*) http://www.couragesteak.com/? permanent;
百度https认证
rewrite ^/(.*) https://www.couragesteak.com? permanent;
注意, 域名后面是?不是 $1,否则也会不通过
./configure: error: the HTTP rewrite module requires the PCRE library
编译时权限不足
/usr/bin/install: cannot create regular file ‘/usr/local/lib/libpcre.so.1.2.13‘: Permission denied
Nginx开启SSL模块
nginx: [emerg] the “ssl” parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:119
查看nginx原有的模块
[root@root sbin]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.20.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
configure arguments: --prefix=$NGINX_HOME
新配置信息就应该这样写
./configure --prefix=$NGINX_HOME --with-http_stub_status_module --with-http_ssl_module
make
这里不要进行make install,否则就是覆盖安装
然后备份原有已安装好的nginx
cp $NGINX_HOME/sbin/nginx $NGINX_HOME/sbin/nginx.bak
然后将刚刚编译好的nginx覆盖掉原有的nginx(这个时候nginx要停止状态)
ps -ef|grep nginx
kill -QUIT 2072
cp ./objs/nginx $NGINX_HOME/sbin/
启动查看
$NGINX_HOME/sbin/nginx
$NGINX_HOME/sbin/nginx -V
方法二
官网:https://ftp.pcre.org/pub/pcre/
sudo wget https://udomain.dl.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.tar.gz
sudo tar -zxvf pcre-8.45.tar.gz
cd pcre-8.45
sudo ./configure
sudo make && make install
configure: error: Invalid C++ compiler or C++ compiler flags
yum install -y gcc-c++
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!