赞
踩
目录
用户知道nginx服务器的存在,与nginx服务器是一伙的。例如:公司内的电脑要通过代理服务器(nginx)连接外网
用户不知道nginx的存在,nginx是与服务端一伙的。
有性能瓶颈,因为所有的数据都经过Nginx,所以Nginx服务器的性能至关重要
- worker_processes 1;
-
-
-
- events {
- worker_connections 1024;
- }
-
-
- http {
- include mime.types;
- default_type application/octet-stream;
-
-
-
- sendfile on;
-
- keepalive_timeout 65;
-
- upstream httpsd {
- server 192.168.23.101:80;
- server 192.168.23.102:80;
- }
- server {
- listen 80;
- server_name localhost;
-
-
- location / {
-
- proxy_pass http://httpsd;
-
- }
-
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
-
-
- }
-
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
- upstream httpd {
- server 127.0.0.1:8050 weight=10 down;
- server 127.0.0.1:8060 weight=1;
- server 127.0.0.1:8060 weight=1 backup;
- }
现在有一台tomcat,一台nginx反向代理tomcat,对于静态资源类型访问通常是比较频繁的,因此将静态资源直接放在nginx服务器上,可以使访问速度快上许多
- location /css {
- root /usr/local/nginx/static;
- index index.html index.htm;
- }
- location /images {
- root /usr/local/nginx/static;
- index index.html index.htm;
- }
- location /js {
- root /usr/local/nginx/static;
- index index.html index.htm;
- }
这里也可以使用正则表达式进行匹配,这样子只需要写一个location
- location ~*/(css|img|js) {
- root /usr/local/nginx/static;
- index index.html index.htm;
- }
- location /css {
- alias /usr/local/nginx/static/css;
- index index.html index.htm;
- }
实例
rewrite ^/([0-9]+).html$ /index.jsp?pageNum=$1 break;
访问:http://192.168.23.100/3.html
真实的访问uri是:http://192.168.23.100/index.jsp?pageNum=3
valid_referers none | blocked | server_names | strings ....;
- valid_referers 192.168.44.101;
- if ($invalid_referer) {
- return 403;
- }
curl -I http://192.168.44.101/img/logo.png
curl -e "http://baidu.com" -I http://192.168.44.101/img/logo.png
使用keepalived维持nginx集群的高可用是比较简单的一种方式,通过安装keepalived并配置keepalived.conf,使得客户端访问一个虚拟ip,当主机nginx挂掉后,从机也能顶上去
https://www.keepalived.org/download.html#
configure: error:!!! OpenSSL is not properly installed on your system. !!!!!! Can not include OpenSSL headers files. !!!
yum install openssl-devel
yum install keepalived
- ! Configuration File for keepalived
-
- global_defs {
-
- router_id lb100
- }
-
- vrrp_instance atguigu {
- state MASTER # 备份服务器上这里写的是BACKUP
- interface ens33 # 网卡的名称
- virtual_router_id 51 # 主备机的virtual_router_id必须相同
- priority 100 # 主备机取不同的优先级,主机值较大,备份机值较小
- advert_int 1 # 隔多久发一次心跳
- authentication {
- auth_type PASS
- auth_pass 1111
- }
- virtual_ipaddress {
- 192.168.23.200
- }
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
第二台机器
- ! Configuration File for keepalived
- global_defs {
- router_id lb110
- }
- vrrp_instance atguigu {
- state BACKUP
- interface ens33
- virtual_router_id 51
- priority 50
- advert_int 1
- authentication {
- auth_type PASS
- auth_pass 1111
- }
- virtual_ipaddress {
- 192.168.44.200
- }
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
systemctl start keepalived
此时在第一台机器上通过ip addr可以看到ens33下有一个虚拟IP 192.168.44.200,第二台机器则没有。把第一台机器关机模拟nginx下线后,第二台机器下也会出现虚拟IP了 。
hadoop100
hadoop101
手动关闭Hadoop100的nginx服务和keepalived服务
此时hadoop100
hadoop101
不安全的http协议
采用对称加密算法(凯撒算法),即客户端和服务器各自有特定的不会变化的钥匙进行加密和解密,灵活性低且不安全
通过域名访问时显示的是不安全的连接
此时通过https://域名的方式请求会发现网站拒绝访问
首先申请SSL证书,这里我们选择阿里云
通过签发后下载nginx的证书
将证书放到nginx的conf目录下,在nginx.conf目录中加入配置,证书会自动在conf目录下查找
server {
listen 443 ssl;
server_name localhost;ssl_certificate pem文件的名字;
ssl_certificate_key key文件的名字;
}
重启nginx.service服务,通过https://域名访问,此时已经显示网站安全
将安装包放到html目录下
在html目录下通过unzip Discuz_X3.4_SC_UTF8_20220131.zip解压
然后通过域名访问bbs/install进行安装即可
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。