差异对比
APACHE | NGINX |
---|---|
配置繁琐 | 配置相对简单 |
原生支持动态和静态页面 | 支持静态页面 |
模块相对安全 | 高性能模块出产迅速、社区活跃 |
BUG 相对较少,消耗资源较多 | BUG相对较多,节省资源 |
对加密支持较好 | 对反向代理支持较好 |
同步阻塞型应用 | 异步非阻塞型应用 |
Nginx 的安装
yum -y install gcc gcc-c++ lrzsz zlib zlib-devel pcre pcre-devel tar -zxvf nginx-xxx tar -zxvf openssl-xxx ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-openssl=/root/openssl-1.0.2h --with-stream && make && make install make && make install
Nginx 实验
1、模块启用
vi /usr/local/nginx/conf/nginx.conf location /abc { stub_status on; }
2、Nginx 访问控制列表(ACL)
-
基于用户名密码的访问控制
vi /usr/local/nginx/conf/nginx.conf location /abc { stub_status on; auth_basic "Welcome to nginx!"; auth_basic_user_file /usr/local/nginx/html/a.psd; } yum -y install httpd htpasswd -c /usr/local/nginx/html/a.psd zhangsan htpasswd -m /usr/local/nginx/html/a.psd lisi
-
基于 IP 的访问控制
vi /usr/local/nginx/conf/nginx.conf location /abc { stub_status on; auth_basic "Welcome to nginx!"; auth_basic_user_file /usr/local/nginx/html/a.psd; allow 192.168.66.250; 允许250拒绝所有 deny 192.168.66.0/24; }
3、虚拟主机
在主配置文件中复制 server{} 区域, 不同的 server 区域则是不同的虚拟主机, 同