微信:tangy8080
电子邮箱:914661180@qq.com
更新时间:2019-07-10 20:56:10 星期三
欢迎您订阅和分享我的订阅号,订阅号内会不定期分享一些我自己学习过程中的编写的文章
如您在阅读过程中发现文章错误,可添加我的微信 tangy8080 进行反馈.感谢您的支持。
了解nginx常用的配置
已经安装好了nginx,如未安装请参考nginx安装和基本配置
auth_basic在nginx里用的应该比较多,经常用于一些不能认证功能应用的基础授权。例如您可以将其用在kibana中
使用openssl来生成,生成命令(openssl在安装nginx的时候已经安装)
echo "kibana:$(openssl passwd -crypt 1234567890)" >>/usr/local/nginx/conf/httpasswd
echo "consul:$(openssl passwd -crypt 1234567890)" >>/usr/local/nginx/conf/httpasswd
echo "etcd:$(openssl passwd -crypt 1234567890)" >>/usr/local/nginx/conf/httpasswd
server{
listen 50813;
location / {
auth_basic "please login";
auth_basic_user_file /usr/local/nginx/conf/httpasswd;
proxy_http_version 1.1;
proxy_pass http://kibana;
}
}
auth_basic_user_file:是用户名和密码的配置文件地址
首先您需要先购买证书,如果只是想用于实验,可以尝试Let’s Encrypt,申请地址:https://www.sslforfree.com/, 需要按照提示在域名管理控制台添加TXT记录
server{
listen 443;
server_name rabbitmq.honeysuckle.site;
ssl on;
ssl_certificate /usr/local/nginx/cert/certificate.crt;
ssl_certificate_key /usr/local/nginx/cert/private.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forward-For $http_x_forwarded_for;
proxy_http_version 1.1;
proxy_pass http://mqweb_backends;
}
}
http {
upstream tomcats {
server 192.168.0.180:8080 weight=1 fail_timeout=20s;
server 192.168.0.181:8080 weight=2 fail_timeout=20s;
}
server {
server_name www.test.com
listen 80;
location / {
proxy_pass http://tomcats;
}
}
}
http {
upstream tomcats {
ip_hash;
server 192.168.0.180:8080 weight=1 fail_timeout=20s;
server 192.168.0.181:8080 weight=2 fail_timeout=20s;
}
server {
server_name www.test.com
listen 80;
location / {
proxy_pass http://tomcats;
}
}
}
使用ip_hash来解决有状态的会话,每个访客固定访问一个后端服务器
http {
upstream tomcats {
fair;
server 192.168.0.180:8080;
server 192.168.0.181:8080;
}
server {
server_name www.test.com
listen 80;
location / {
proxy_pass http://tomcats;
}
}
}
按后端服务器的响应时间来分配请求,响应时间短的优先分配。
http {
upstream tomcats {
hash $request_uri;
server 192.168.0.180:8080;
server 192.168.0.181:8080;
}
server {
server_name www.test.com
listen 80;
location / {
proxy_pass http://tomcats;
}
}
}
按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有效
https://www.cnblogs.com/yinzhengjie/p/7788237.html
手机扫一扫
移动阅读更方便
你可能感兴趣的文章