高性能web服务器nginx
Nginx 概述
Nginx 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。它以轻量级、高并发处理能力和低资源消耗而闻名,广泛用于构建 Web 服务器、负载均衡器、反向代理等场景。
主要特点:
- 高性能:采用异步处理大量并发连接,采用异步非阻塞的事件驱动模型。
- 高可靠性:设计稳定,能够在高负载下保持可靠运行。
- 模块化架构:支持多种模块扩展,可根据需求灵活配置。
- 反向代理和负载均衡:能将客户端请求分发到多个后端服务器,提高系统可用性和性能。
- 静态资源服务:高效处理静态文件(如 HTML、CSS、JavaScript、图片等)。
- SSL/TLS 支持:可配置 HTTPS,保障数据传输安全。
nginx安装
[root@localhost ~]# cd /mnt
[root@localhost mnt]# tar zxf nginx-1.24.0.tar.gz
[root@localhost mnt]# ls
hgfs nginx-1.24.0 nginx-1.24.0.tar.gz
[root@localhost mnt]# cd nginx-1.24.0
[root@localhost nginx-1.24.0]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
[root@Nginx nginx-1.24.0]# useradd -s /sbin/nologin -M nginx
[root@localhost nginx-1.24.0]# ./configure --prefix=/usr/local/nginx \
--user=nginx \
> --group=nginx \
> --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
[root@localhost nginx-1.24.0]# dnf install gcc pcre-devel zlib-devel openssl-devel -y
[root@localhost nginx-1.24.0]# make
[root@localhost nginx-1.24.0]# make install
[root@localhost nginx-1.24.0]# cd /usr/local/nginx/sbin/
[root@localhost sbin]# ls
nginx
[root@localhost sbin]# ./nginx
[root@localhost sbin]# netstat -antlupe | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 0 84096 46931/nginx: master
[root@localhost sbin]# echo "export PATH=$PATH:/usr/local/nginx/sbin" >> ~/.bash_profile
[root@localhost sbin]# cat ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then. ~/.bashrc
fi
# User specific environment and startup programs
export PATH=/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/nginx/sbin
[root@localhost sbin]# source ~/.bash_profile
[root@localhost sbin]# nginx -v
nginx version: nginx/1.24.0
[root@localhost ~]# ls /usr/local/nginx/
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
conf:保存nginx所有的配置文件,其中nginx.conf是nginx服务器的最核心最主要的配置文件,其他 的.conf则是用来配置nginx相关的功能的,例如fastcgi功能使用的是fastcgi.conf和fastcgi_params 两个文件,配置文件一般都有一个样板配置文件,是以.default为后缀,使用时可将其复制并将default后缀 去掉即可。 html目录中保存了nginx服务器的web文件,但是可以更改为其他目录保存web文件,另外还有一个50x的web 文件是默认的错误页面提示页面。 logs:用来保存nginx服务器的访问日志错误日志等日志,logs目录可以放在其他路径,比 如/var/logs/nginx里面。 sbin:保存nginx二进制启动脚本,可以接受不同的参数以实现不同的功能。
实现nginx高并发配置
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
user nginx;
worker_processes auto;
worker_cpu_affinity 0001 0010 0100 1000;
worker_rlimit_nofile 100000;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {worker_connections 100000;use epoll;
}
[root@localhost ~]# nginx -t
[root@localhost ~]# nginx -s reload
安装httpd-tools工具实现高并发的访问
新建一个 PC web 站点
访问172.25.254.20,默认是172.25.254.20,访问www.wan.org,自定义为“web_html”。
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
include "/usr/local/nginx/conf.d/*.conf";
[root@localhost ~]# mkdir -p /web/html
[root@localhost ~]# echo web_html > /web/html/index.html
[root@localhost ~]# mkdir -p /usr/local/nginx/conf.d
[root@localhost ~]# cd /usr/local/nginx/conf.d
[root@localhost conf.d]# ls
[root@localhost conf.d]# vim vhosts.conf
server {listen 80;server_name www.wan.org;root /web/html;index index.html;
}
[root@localhost conf.d]# nginx -s reload
[root@localhost conf.d]# vim /etc/hosts
172.25.254.20 www.wan.org
测试
root和alias
root:指定web的家目录,在定义location的时候,文件的绝对路径等于 root+location
[root@localhost conf.d]# vim vhosts.conf
server {listen 80;server_name www.wan.org;location / {root /web/html;}
location /dirtest {root /mnt;}
}
[root@localhost conf.d]# nginx -s reload
[root@localhost ~]# mkdir -p /mnt/dirtest
[root@localhost ~]# echo dirtest page > /mnt/dirtest/index.html
测试
alias:定义路径别名,会把访问的路径重新定义到其指定的路径,文档映射的另一种机制;仅能用于 location上下文,此指令使用较少
[root@localhost conf.d]# vim vhosts.conf
server {listen 80;server_name www.wan.org;location / {root /web/html;}
location /dirtest {root /mnt;}location /alias { #注意about后不要加/alias /mnt/dirtest; # 使用alias的时候uri后面如果加了斜杠,则下面的 路径配置必须加斜杠,否则403} # 当访问alias的时候,会显示alia定义 的/mnt/dirtest里面的内容 }
[root@localhost conf.d]# nginx -s reload
测试
nginx 账户认证功能
#创建nginx所需认证文件
[root@localhost ~]# htpasswd -cm /usr/local/nginx/.htpasswd admin
New password:
Re-type new password:
Adding password for user admin
[root@localhost ~]# cat /usr/local/nginx/.htpasswd
admin:$apr1$8PsjsdRA$VEa98V6t4ME.CzmlADJNX/#当认证文件不存在是需要用-c建立#当认证文件存在是如果加-c参数会覆盖原文件内容
[root@localhost ~]# htpasswd -m /usr/local/nginx/.htpasswd wan
New password:
Re-type new password:
Adding password for user wan
[root@localhost ~]# cat /usr/local/nginx/.htpasswd
admin:$apr1$8PsjsdRA$VEa98V6t4ME.CzmlADJNX/
wan:$apr1$8vZuERf8$o2O.MWCgRdFccC0gwJCmV.
[root@localhost ~]# cd /usr/local/nginx/conf.d
[root@localhost conf.d]# vim vhosts.conf
location /login/ {root /web/;index index.html;auth_basic "Please input username and password";auth_basic_user_file /usr/local/nginx/.htpasswd;}
[root@localhost conf.d]# nginx -t
[root@localhost conf.d]# nginx -s reload
[root@localhost ~]# mkdir -p /web/login
[root@localhost ~]# echo login > /web/login/index.html
自定义错误页面
[root@localhost ~]# cd /usr/local/nginx/conf.d
[root@localhost conf.d]# vim vhosts.conf
server {listen 80;server_name www.wan.org;index index.html;error_page 500 502 503 504 404 /errorpage/error.html;location / {root /web/html;location /errorpage {root /web/;}
}
[root@localhost conf.d]# nginx -t
[root@localhost conf.d]# nginx -s reload
[root@localhost ~]# mkdir -p /web/errorpage
[root@localhost ~]# ehco sorry > /web/errorpage/error.html
自定义日志
[root@localhost ~]# cd /usr/local/nginx/conf.d
[root@localhost conf.d]# vim vhosts.conf
server {listen 80;server_name www.wan.org;index index.html;error_page 500 502 503 504 404 /errorpage/error.html;error_log /usr/local/nginx/logs/wan.org.err;access_log /usr/local/nginx/logs/wan.org.access;location / {root /web/html;}location /dirtest {root /mnt;}location /errorpage {root /web/;}
}
[root@localhost conf.d]# nginx -t
[root@localhost conf.d]# nginx -s reload
长链接
[root@localhost ~]# cd /usr/local/nginx/conf/
[root@localhost conf]# vim nginx.confhttp{keepalive_timeout 10; # 一次连接10秒自动断开}
[root@localhost conf]# nginx -t
[root@localhost conf]# nginx -s reload
[root@localhost conf]# dnf install telnet -y
连接三次后自动断开
[root@localhost conf]# vim nginx.conf
http{keepalive_timeout 10; # 测试超时时,只需要一次测试过程完成后等待即可keepalive_requests 3; # 测试限定次数 需要完成指定次数测试过程会自动断开
}
作为下载服务器配置
[root@localhost ~]# cd /usr/local/nginx/conf.d
[root@localhost conf.d]# vim vhosts.conf
server {listen 80;server_name www.wan.org;index index.html;error_page 500 502 503 504 404 /errorpage/error.html;error_log /usr/local/nginx/logs/wan.org.err;access_log /usr/local/nginx/logs/wan.org.access;try_files $uri $uri.html $uri/index.html /errorpage/default.html;location / {root /web/html;}location /dirtest {root /mnt;}location /alias {alias /mnt/dirtest;}location /errorpage {root /web/;}location /download/ {root /web/;autoindex on;autoindex_localtime on;autoindex_exact_size off;autoindex_format html;set $limit_rate 1024k;}
}
[root@localhost conf.d]# nginx -t
[root@localhost conf.d]# nginx -s reload
[root@localhost ~]# mkdir -p /web/download #共享资源存放目录
[root@localhost ~]# dd if=/dev/zero of=/web/download/test bs=lM count=50
状态页
location /status {stub_status;auth_basic "status page";auth_basic_user_file "usr/local/nginx/.htpasswd";}
nginx压缩功能
[root@localhost ~]# cd /usr/local/nginx/conf
[root@localhost conf]# vim nginx.confhttp{ gzip on;gzip_comp_level 4;gzip_disable "MSIE [1-6]\.";gzip_min_length 1k;gzip_vary on;gzip_static on;}[root@localhost conf]# nginx -s reload
[root@localhost conf]# nginx -t
#big.html必须大于1k
[root@localhost conf]# ls -l /usr/local/nginx/html/big.html
-rw-r--r--. 1 root root 1915 7月 26 15:15 /usr/local/nginx/html/big.html
[root@localhost ~]# curl --head --compressed 172.25.254.20/big.html
ngx_http_rewrite_module 模块指令
if指令
location /test {index index.html;default_type text/html;if ( $scheme = http ){echo "if ---------> $scheme";}if ( $scheme = https ){echo "if ---------> $scheme";}}location /test2 {if ( !-e $request_filename ){echo "$request_filename is not exist";return 409;}}
set指令
[root@localhost ~]# vim /usr/local/nginx/conf.d/vhosts.conf
server {listen 80;server_name www.wan.org;root /webdata/nginx/wan.org/wan;location /test3{set $name wan;echo $name;}
}
break指令
[root@localhost ~]# vim /usr/local/nginx/conf.d/vhosts.conf
server {listen 80;server_name www.wan.org;root /webdata/nginx/wan.org/wan;location /break{default_type text/html;set $name wan;echo $name;break;set $port $server_port;echo $port;}
}
return指令
[root@localhost ~]# vim /usr/local/nginx/conf.d/vhosts.conf
server {listen 80;server_name www.wan.org;root /webdata/nginx/wan.org/wan;location /return {default_type text/html;if ( !-e $request_filename){return 301 http://www.baidu.com;#return 666 "$request_filename is not exist";}echo "$request_filename is exist";}
}
反向代理
部署 Apache服务器
[root@localhost ~]# dnf install httpd -y
[root@localhost ~]# echo "web1 172.25.254.10" > /var/www/html/index.html
[root@localhost ~]# systemctl enable --now httpd
[root@localhost ~]# dnf install httpd -y
[root@localhost ~]# echo "web2 172.25.254.20" >> /var/www/html/index.html
[root@localhost ~]# systemctl enable --now httpd[root@localhost ~]# curl http://172.25.254.10
web1 172.25.254.10
[root@localhost ~]# curl http://172.25.254.11
web2 172.25.254.11
配置 nginx 反向代理
[root@localhost ~]# cat /apps/nginx/conf/conf.d/pc.conf
upstream webserver { #ip_hash;#hash $request_uri consistent;#hash $cookie_wan#least_conn;server 172.25.254.10:8080 weight=1;server 172.25.254.11:80 weight=1;server 172.25.254.12:80 backup;
}
server {listen 80;server_name www.wan.org;location ~ / {proxy_pass http://webserver;}
重启Nginx 并访问测试
[root@localhost ~]# curl www.wan.org
172.25.254.10 web
[root@localhost ~]# curl www.wan.org
172.25.254.11 web
关闭172.25.254.20和172.25.254.30,测试nginx backup服务器可用性:
[root@localhost ~]# while true;do curl
http://www.wan.org;sleep 1;done
实现 Nginx 四层负载均衡
安装myriadb
172.25.254.10 172.25.254.11
[root@localhost ~]# dnf install myriadb-server -y
[root@localhost ~]# mysql -e "grant all on *.* to wan@'%' identified by 'wan';"
[root@localhost ~]# vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
server_id=10
[root@localhost ~]# systemctl start mariadb.service
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.5.22-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select @@server_id-> ;
+-------------+
| @@server_id |
+-------------+
| 10 |
+-------------+
1 row in set (0.000 sec)
[root@localhost ~]# dnf install myriadb-server -y
[root@localhost ~]# mysql -e "grant all on *.* to wan@'%' identified by 'wan';"
[root@localhost ~]# vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
server_id=11
[root@localhost ~]# systemctl start mariadb.service
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.5.22-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select @@server_id-> ;
+-------------+
| @@server_id |
+-------------+
| 11 |
+-------------+
1 row in set (0.000 sec)
客户端测试
实现fastcgi
[root@localhost php-8.3.9]# dnf install libcurl-devel.x86_64 -y
[root@localhost php-8.3.9]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-curl --with-iconv --with-mhash --with-zlib --with-openssl --enable-mysqlnd --with-mysqli --with-pdo-mysql --disable-debug --enable-sockets --enable-soap --enable-xml --enable-ftp --enable-gd --enable-exif --enable-mbstring --enable-bcmath --with-fpm-systemd
[root@localhost php-8.3.9]# make
[root@localhost php-8.3.9]# make install
[root@localhost php-8.3.9]# cd /usr/local/php/etc
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# ls
php-fpm.conf php-fpm.conf.default php-fpm.d
[root@localhost etc]# vim php-fpm.conf
#去掉注释
pid = run/php-fpm.pid
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# vim www.conf
listen=0.0.0.0:9000
[root@localhost php-8.3.9]# cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-8.3.9]# vim /usr/local/php/etc/php.ini
[Date]
; Defines the default timezone used by the date functions
; https://php.net/date.timezone
date.timezone = Asia/Shanghai #修改时区
[root@localhost php-8.3.9]# cp sapi/fpm/php-fpm.service /lib/systemd/system/php-fpm.service
[root@localhost php-8.3.9]# vim /lib/systemd/system/php-fpm.service
[root@localhost php-8.3.9]# systemctl enable --now php-fpm.service
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@localhost php-8.3.9]# netstat -antlupe l grep php-fpm
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:9000 0.0.0.0:* LISTEN 0 199249 199967/php-fpm: mas
php测试页面
[root@localhost system]# cd /usr/local/nginx/html/
[root@localhost html]# vim index.php
<?
phpinfo();
?>
Nginx配置转发
[root@localhost ~]# cd /usr/local/nginx/conf.d
[root@localhost conf.d]# vim vhosts.conf
server{listen 80;server_name www.wan.org;error_log /usr/local/nginx/logs/wan.org.err;access_log /usr/local/nginx/logs/wan.org.access;root /usr/local/nginx/html/;location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;include fastcgi.conf;}}
[root@localhost conf.d]# nginx -t
[root@localhost conf.d]# nginx -s reload
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls
dirtest hgfs nginx-1.24.0 nginx-1.24.0.tar.gz oniguruma-6.9.6-1.el9.6.x86_64.rpm oniguruma-devel-6.9.6-1.el9.6.x86_64.rpm
[root@localhost mnt]# dnf update oniguruma-6.9.6-1.el9.6.x86_64.rpm
[root@localhost mnt]# dnf install oniguruma-devel-6.9.6-1.el9.6.x86_64.rpm -y
php的动态扩展模块
安装memcache模块
[root@Nginx ~]# tar zxf memcache-8.2.tgz
[root@localhost ~]# dnf install php-devel -y
[root@localhost memcache-8.2]# phpize
Configuring for:
PHP Api Version: 20200930
Zend Module Api No: 20200930
Zend Extension Api No: 420200930
[root@Nginx ~]# cd memcache-8.2/
[root@localhost memcache-8.2]# ./configure
[root@localhost memcache-8.2]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20230831/
[root@localhost memcache-8.2]# ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20230831
memcache.so opcache.so#复制测试文件到nginx发布目录中
[root@localhost memcache-8.2]# cp example.php memcache.php /usr/local/nginx/html
[root@localhost ~]# vim /usr/local/nginx/html/memcache.php
$VERSION='$Id$';define('ADMIN_USERNAME','admin'); // Admin Username
define('ADMIN_PASSWORD','123456'); // Admin Password
define('DATE_FORMAT','Y/m/d H:i:s');
define('GRAPH_SIZE',200);
define('MAX_ITEM_DUMP',50);
$MEMCACHE_SERVERS[] = 'mymemcache-server1:11211'; // add more as an array
#$MEMCACHE_SERVERS[] = '127.0.0.1:11211'; // add more as an array
配置php加载memcache模块
[root@localhost ~]# vim /usr/local/php/etc/php.ini
;extension=zip
extension=memcache
;zend_extension=opcache
[root@localhost ~]# systemctl reload php-fpm
[root@Nginx no-debug-non-zts-20230831]# php -m | grep mem
memcache
部署memcached
[root@localhost ~]# dnf install memcached -y
[root@localhost ~]# systemctl enable --now memcached.service
[root@localhost ~]# netstat -antlupe | grep memcache
tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN 980 278629 264250/memcached
tcp6 0 0 ::1:11211 :::* LISTEN 980 278630 264250/memcached
[root@localhost ~]# cat /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS="-l 127.0.0.1,::1"
访问 http://www.wan.org/example.php 不断刷新
访问 http://www.wan.org/memcache.php 查看命中效果
php高速缓存
[root@localhost ~]# ls
公共 音乐 memcache-8.2.tgz php-8.3.9.tar.gz
模板 桌面 memc-nginx-module-0.20 srcache-nginx-module-0.33
视频 anaconda-ks.cfg memc-nginx-module-0.20.tar.gz srcache-nginx-module-0.33.tar.gz
图片 echo-nginx-module-0.63 openresty-1.25.3.1.tar.gz
文档 echo-nginx-module-0.63.tar.gz package.xml
下载 memcache-8.2 php-8.3.9
[root@localhost ~]# cd /mnt/nginx-1.24.0/
[root@localhost conf.d]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --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 --add-module=/root/echo-nginx-module-0.63 --add-module=/root/memc-nginx-module-0.20 --add-module=/root/srcache-nginx-module-0.33
[root@localhost nginx-1.24.0]# make && make install -y
[root@localhost nginx-1.24.0]# cd /usr/local/nginx/conf
[root@localhost conf]# vim nginx.conf
include "/usr/local/nginx/conf.d/*.conf";
[root@localhost nginx-1.24.0]# nginx -V
nginx version: nginx/1.24.0
built by gcc 11.4.1 20231218 (Red Hat 11.4.1-3) (GCC)
built with OpenSSL 3.0.7 1 Nov 2022
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --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 --add-module=/root/echo-nginx-module-0.63 --add-module=/root/memc-nginx-module-0.20 --add-module=/root/srcache-nginx-module-0.33
[root@localhost nginx-1.24.0]# cd /usr/local/nginx/conf.d
[root@localhost conf.d]# vim vhosts.conf
upstream memcache {server 127.0.0.1:11211;keepalive 512;
}server {listen 80;server_name www.wan.org;location /mcmc {internal;memc_connect_timeout 100ms;memc_send_timeout 100ms;memc_read_timeout 100ms;set $memc_key $query_string;set $memc_exptime 300;memc_pass memcache;}location ~ \.php$ {set $key $uri$args;# 修正缓存路径引用,与上面定义的/mcmc保持一致srcache_fetch GET /mcmc $key;srcache_store PUT /mcmc $key;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;include fastcgi.conf;}
}
[root@localhost conf.d]# nginx -t
[root@localhost conf.d]# nginx -s reload
测试
[root@localhost conf.d]# ab -n1000 -c50 http://www.wan.org/index.php
失败请求数(0
表示无请求报错,服务稳定性佳)。
nginx 二次开发版本
openresty
Nginx 是俄罗斯人发明的, Lua 是巴西几个教授发明的,中国人章亦春把 LuaJIT VM 嵌入到 Nginx 中, 实现了 OpenResty 这个高性能服务端解决方案
OpenResty® 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方 模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服 务和动态网关。
OpenResty® 通过汇聚各种设计精良的 Nginx 模块(主要由 OpenResty 团队自主开发),从而将Nginx 有效地变成一个强大的通用 Web 应用平台。这样,Web 开发人员和系统工程师可以使用 Lua 脚本语言 调动 Nginx 支持的各种 C 以及 Lua 模块,快速构造出足以胜任 10K 乃至 1000K 以上单机并发连接的高 性能 Web 应用系统。
OpenResty 由于有功能强大且方便的的API,可扩展性更强,如果需要实现定制功能,OpenResty是个不错的选择
官网: http://openresty.org/cn/
编译安装 openresty
[root@localhost ~]# dnf -yq install gcc pcre-devel openssl-devel perl zlib-devel
[root@localhost ~]# useradd -r -s /sbin/nologin nginx
[root@localhost ~]# tar zxf openresty-1.25.3.1.tar.gz
[root@localhost ~]# cd openresty-1.25.3.1/
[root@localhost openresty-1.25.3.1]# ls
bundle configure COPYRIGHT patches README.markdown README-windows.txt util
[root@localhost openresty-1.25.3.1]# ./configure \
--prefix=/apps/openresty \
--user=nginx --group=nginx \
--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
[root@localhost openresty-1.25.3.1]# gmake
[root@localhost openresty-1.25.3.1]# make install
编辑主文件
[root@localhost ~]# vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/apps/nginx/sbin:/usr/local/php/bin:/apps/openresty/bin
[root@localhost ~]# source ~/.bash_profile
测试并启动openrestry
[root@localhost ~]# openresty -t
nginx: the configuration file /apps/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/openresty/nginx/conf/nginx.conf test is successful
[root@localhost ~]# openresty
[root@localhost ~]# openresty -v
nginx version: openresty/1.25.3.1