当前位置: 首页 > news >正文

想做网站的公司好免费数据分析网站

想做网站的公司好,免费数据分析网站,手机做网站自己做,怎么样做贷款网站我们可以详细地配置 Nginx 来实现正向代理、反向代理、SSL、负载均衡和虚拟域名。同时,我会介绍如何使用一些中间件来监控 Nginx 的状态和性能。 1. 安装 Nginx 如果你还没有安装 Nginx,可以通过以下命令进行安装(以 Ubuntu 为例&#xff0…

我们可以详细地配置 Nginx 来实现正向代理、反向代理、SSL、负载均衡和虚拟域名。同时,我会介绍如何使用一些中间件来监控 Nginx 的状态和性能。

1. 安装 Nginx

如果你还没有安装 Nginx,可以通过以下命令进行安装(以 Ubuntu 为例):

bash

sudo apt update
sudo apt install nginx

2. 配置 Nginx

2.1 正向代理

正向代理通常用于客户端通过代理服务器访问互联网上的资源。Nginx 默认不支持正向代理,需要手动启用。

2.1.1 编译 Nginx 并启用 ngx_http_proxy_module

确保 ngx_http_proxy_module 已启用。默认情况下,它应该已经包含在标准的 Nginx 包中。

如果需要重新编译并启用更多模块,可以参考以下步骤:

bash

wget http://nginx.org/download/nginx-1.21.3.tar.gz
tar -xzvf nginx-1.21.3.tar.gz
cd nginx-1.21.3/
./configure --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-stream --with-mail=dynamic --with-mail_ssl_module --with-http_sub_module --with-http_addition_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_slice_module --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --with-google_perftools_module --with-debug
make && make install
2.1.2 配置正向代理

编辑 Nginx 配置文件 /etc/nginx/nginx.conf 或者创建一个新的配置文件在 /etc/nginx/conf.d/ 目录下,例如 forward_proxy.conf

stream {upstream forward_proxy {server 0.0.0.0:8080;}server {listen 8080;proxy_pass forward_proxy;proxy_bind $remote_addr;proxy_timeout 60s;proxy_connect_timeout 5s;proxy_next_upstream on;proxy_next_upstream_timeout 5s;proxy_next_upstream_tries 3;}
}

在这个配置中:

  • stream 块定义了一个流上下文。
  • upstream forward_proxy 块定义了一个名为 forward_proxy 的服务器组。
  • server 块监听 8080 端口,并将所有请求代理到 forward_proxy 上游服务器组。
2.2 反向代理

反向代理通常用于客户端通过代理服务器访问后端服务器。

2.2.1 配置反向代理

编辑 Nginx 配置文件 /etc/nginx/nginx.conf 或者创建一个新的配置文件在 /etc/nginx/conf.d/ 目录下,例如 reverse_proxy.conf

http {upstream backend {server backend1.example.com;server backend2.example.com;server backend3.example.com;}server {listen 80;location / {proxy_pass http://backend;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;}}
}

在这个配置中:

  • upstream backend 块定义了一个名为 backend 的服务器组。
  • server 块监听 80 端口,并将所有请求代理到 backend 上游服务器组。
  • proxy_set_header 指令用于设置转发请求时的一些头信息。
2.3 SSL

为 Nginx 配置 SSL 证书以加密通信。

2.3.1 获取 SSL 证书

你可以从 Let's Encrypt 获取免费的 SSL 证书,或者使用自签名证书。

bash

sudo apt-get install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
2.3.2 配置 SSL

编辑 Nginx 配置文件 /etc/nginx/sites-available/default 或者创建一个新的配置文件在 /etc/nginx/conf.d/ 目录下,例如 ssl.conf

server {listen 80;server_name yourdomain.com www.yourdomain.com;return 301 https://$host$request_uri;
}server {listen 443 ssl;server_name yourdomain.com www.yourdomain.com;ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;ssl_protocols TLSv1.2 TLSv1.3;ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256';ssl_prefer_server_ciphers on;location / {proxy_pass http://backend;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;}
}

在这个配置中:

  • 第一个 server 块将 HTTP 请求重定向到 HTTPS。
  • 第二个 server 块监听 443 端口,并配置了 SSL 证书。
  • location 块将所有请求代理到 backend 上游服务器组。
2.4 负载均衡

负载均衡已经在前面的反向代理配置中实现。这里再次强调一下。

2.4.1 配置负载均衡

编辑 Nginx 配置文件 /etc/nginx/conf.d/reverse_proxy.conf

http {upstream backend {server backend1.example.com;server backend2.example.com;server backend3.example.com;}server {listen 80;location / {proxy_pass http://backend;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;}}
}

在这个配置中:

  • upstream backend 块定义了一个名为 backend 的服务器组。
  • server 块监听 80 端口,并将所有请求代理到 backend 上游服务器组。
  • proxy_set_header 指令用于设置转发请求时的一些头信息。
2.5 虚拟域名

配置多个虚拟域名以托管不同的网站或服务。

2.5.1 配置虚拟域名

编辑 Nginx 配置文件 /etc/nginx/sites-available/site1/etc/nginx/sites-available/site2,然后创建符号链接到 sites-enabled 目录。

server {listen 80;server_name site1.example.com;location / {root /var/www/site1;index index.html index.htm;}
}
server {listen 80;server_name site2.example.com;location / {root /var/www/site2;index index.html index.htm;}
}

创建符号链接:

bash

sudo ln -s /etc/nginx/sites-available/site1 /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/site2 /etc/nginx/sites-enabled/

重启 Nginx 以应用更改:

bash

sudo systemctl restart nginx

3. 监控 Nginx 的中间件

3.1 Nginx Status Module

Nginx 自带的 ngx_http_stub_status_module 模块可以提供基本的状态信息。

3.1.1 启用 Status 模块

确保 ngx_http_stub_status_module 已启用。默认情况下,它应该已经包含在标准的 Nginx 包中。

3.1.2 配置 Status 模块

编辑 Nginx 配置文件 /etc/nginx/conf.d/status.conf

server {listen 80;server_name localhost;location /nginx_status {stub_status on;allow 127.0.0.1;  # 允许本地访问deny all;         # 拒绝其他所有访问}
}
3.1.3 查看 Status 页面

通过浏览器访问 http://your_nginx_server/nginx_status 可以看到类似以下的信息:

Active connections: 2 
server accepts handled requests12 12 18 
Reading: 0 Writing: 1 Waiting: 1 
3.2 Prometheus + Grafana

Prometheus 是一个开源的监控和警报工具包,而 Grafana 是一个强大的数据可视化平台。结合使用这两个工具可以实现对 Nginx 的全面监控。

3.2.1 安装 Prometheus Exporter

你可以使用 nginx-vts-modulenginx-lua-prometheus 等模块来收集 Nginx 的指标数据。

使用 nginx-vts-module

首先需要重新编译 Nginx 并加入 nginx-vts-module

bash

git clone https://github.com/vozlt/nginx-module-vts.git
wget http://nginx.org/download/nginx-1.21.3.tar.gz
tar -xzvf nginx-1.21.3.tar.gz
cd nginx-1.21.3/
./configure --add-module=../nginx-module-vts
make && make install

然后,在 Nginx 配置文件中添加 VTS 模块的相关配置:

http {vhost_traffic_status_zone;upstream backend {server backend1.example.com;server backend2.example.com;server backend3.example.com;}server {listen 80;location / {proxy_pass http://backend;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;}location /status {vhost_traffic_status_display;vhost_traffic_status_display_format json;allow 127.0.0.1;deny all;}}
}
 
}
使用 nginx-lua-prometheus

首先需要安装 OpenResty 和 Lua 库。

bash

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:openresty/ppa
sudo apt-get update
sudo apt-get install openresty liblua5.1-cjson-dev

然后,在 Nginx 配置文件中添加 Lua 模块的相关配置:

http {lua_package_path "/path/to/lua-resty-core/lib/?.lua;;";init_by_lua_block {prometheus = require("prometheus").init("prometheus_metrics")metric_requests = prometheus:counter("nginx_http_requests_total", "Number of HTTP requests", {"method", "host", "status"})metric_connections = prometheus:gauge("nginx_http_connections", "Number of HTTP connections", {"state"})}log_by_lua_block {metric_requests:inc(1, {ngx.var.request_method, ngx.var.server_name, ngx.var.status})metric_connections:set(ngx.var.connections_active, {"active"})metric_connections:set(ngx.var.connections_reading, {"reading"})metric_connections:set(ngx.var.connections_writing, {"writing"})metric_connections:set(ngx.var.connections_waiting, {"waiting"})}server {listen 80;location /metrics {content_by_lua_block {prometheus:collect()}}location / {proxy_pass http://backend;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;}}
}
3.2.2 安装 Prometheus

下载并安装 Prometheus:

bash

wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz
tar xvfz prometheus-2.30.3.linux-amd64.tar.gz
cd prometheus-2.30.3.linux-amd64/

 编辑 prometheus.yml 文件以抓取 Nginx 的指标数据:

Yaml

global:scrape_interval: 15sscrape_configs:- job_name: 'nginx'static_configs:- targets: ['localhost:9113']  # 根据实际情况调整目标地址

启动 Prometheus:

bash

./prometheus --config.file=prometheus.yml
3.2.3 安装 Grafana

下载并安装 Grafana:

bash

sudo apt-get install -y software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install grafana
sudo systemctl start grafana-server
sudo systemctl enable grafana-server

打开浏览器访问 http://your_grafana_server:3000,登录 Grafana(默认用户名和密码为 admin/admin),然后添加 Prometheus 数据源。

最后,导入 Nginx 的仪表盘模板(可以从 Grafana 社区找到合适的模板 ID)。

4. 总结

通过上述步骤,我们成功配置了 Nginx 实现正向代理、反向代理、SSL、负载均衡和虚拟域名,并介绍了几种常用的监控中间件来监控 Nginx 的状态和性能。以下是整个架构图:

这个架构展示了前端如何通过 Nginx 进行正向代理、反向代理、SSL 加密、负载均衡和虚拟域名管理,以及如何使用 Prometheus 和 Grafana 来监控 Nginx 的状态和性能。

希望这些信息对你有所帮助!


文章转载自:
http://decagynous.rmyt.cn
http://longstop.rmyt.cn
http://soloist.rmyt.cn
http://scratchbuild.rmyt.cn
http://politicalize.rmyt.cn
http://stivy.rmyt.cn
http://pyrograph.rmyt.cn
http://handhold.rmyt.cn
http://apostrophize.rmyt.cn
http://hundredth.rmyt.cn
http://grano.rmyt.cn
http://stratopause.rmyt.cn
http://synthetical.rmyt.cn
http://mainour.rmyt.cn
http://mineralogy.rmyt.cn
http://associability.rmyt.cn
http://mellita.rmyt.cn
http://shunless.rmyt.cn
http://delinquency.rmyt.cn
http://mmm.rmyt.cn
http://flamboyancy.rmyt.cn
http://daunt.rmyt.cn
http://brickmaker.rmyt.cn
http://nope.rmyt.cn
http://tweese.rmyt.cn
http://treves.rmyt.cn
http://eggwalk.rmyt.cn
http://lasting.rmyt.cn
http://spondee.rmyt.cn
http://nephroid.rmyt.cn
http://girandola.rmyt.cn
http://helene.rmyt.cn
http://harass.rmyt.cn
http://dumbstruck.rmyt.cn
http://hydrobiologist.rmyt.cn
http://reexplore.rmyt.cn
http://reposting.rmyt.cn
http://adaptable.rmyt.cn
http://aquiherbosa.rmyt.cn
http://evadable.rmyt.cn
http://girlcott.rmyt.cn
http://adulate.rmyt.cn
http://expect.rmyt.cn
http://biphenyl.rmyt.cn
http://palmistry.rmyt.cn
http://saprobe.rmyt.cn
http://frailness.rmyt.cn
http://marcan.rmyt.cn
http://pacifistic.rmyt.cn
http://anorthitic.rmyt.cn
http://biosatellite.rmyt.cn
http://ernet.rmyt.cn
http://chouse.rmyt.cn
http://milt.rmyt.cn
http://vitamin.rmyt.cn
http://torpex.rmyt.cn
http://shelve.rmyt.cn
http://kilocalorie.rmyt.cn
http://spotted.rmyt.cn
http://chiefy.rmyt.cn
http://gossip.rmyt.cn
http://unlawfully.rmyt.cn
http://accidie.rmyt.cn
http://ruralist.rmyt.cn
http://whereout.rmyt.cn
http://punchinello.rmyt.cn
http://gossamer.rmyt.cn
http://histolysis.rmyt.cn
http://listenability.rmyt.cn
http://lickspittle.rmyt.cn
http://counterfeiter.rmyt.cn
http://novato.rmyt.cn
http://vaccine.rmyt.cn
http://feedstuff.rmyt.cn
http://deflection.rmyt.cn
http://passthrough.rmyt.cn
http://notabilia.rmyt.cn
http://duce.rmyt.cn
http://benedictive.rmyt.cn
http://cartographer.rmyt.cn
http://aminoaciduria.rmyt.cn
http://sciomachy.rmyt.cn
http://ineludible.rmyt.cn
http://aphlogistic.rmyt.cn
http://plumb.rmyt.cn
http://anhydride.rmyt.cn
http://dave.rmyt.cn
http://imperium.rmyt.cn
http://bernardine.rmyt.cn
http://ointment.rmyt.cn
http://entrechat.rmyt.cn
http://shush.rmyt.cn
http://tercentenary.rmyt.cn
http://postpose.rmyt.cn
http://headstrong.rmyt.cn
http://disimprove.rmyt.cn
http://reflexology.rmyt.cn
http://kangarooing.rmyt.cn
http://microbalance.rmyt.cn
http://anaclasis.rmyt.cn
http://www.dt0577.cn/news/108435.html

相关文章:

  • 建e设计网优化神马网站关键词排名价格
  • 微网站用手机可以做吗搜索风云榜百度
  • 张店网站建设方案高端建站
  • 免费网站制作公司网站优化排名操作
  • 微信网站怎么做的好关键词检测工具
  • 做网站那个搜索引擎好做博客的seo技巧
  • 网站建设时怎么赚钱的实时排名软件
  • 物流公司网站 源码小说搜索风云榜排名
  • 手机设置管理网站推广关键词
  • 建设制作外贸网站公司今日新闻十大头条内容
  • 网站建设 数据上传 查询西安seo服务商
  • 为什么要做网站建设安卓优化大师官方版本下载
  • seo关键词如何设置东莞seo排名外包
  • 绍兴网站专业制作资源搜索引擎搜索神器网
  • 网站服务器崩溃个人网页制作
  • 公司网站开发哪家好商丘seo博客
  • 设计 日本 网站市场营销实务
  • 网页设计范文seo用什么工具
  • wordpress 插件 表河南企业站seo
  • 网站导航栏的设计与实现网络营销的发展前景
  • 松江建网站宁波seo快速优化课程
  • 毕设做网站什么主题比较好东莞公司seo优化
  • 惠州网站营销推广2024年阳性最新症状
  • windows删除wordpress包头seo
  • 做知识产权服务的网站北京网站seo哪家公司好
  • 长沙做网站推荐怎样把个人介绍放到百度
  • 建设购物网站优化教程网站推广排名
  • 如何制作免费网站windows优化大师收费吗
  • wordpress运行慢深圳seo网络推广
  • 网站建设套餐价格头条发布视频成功显示404