配置nginx代理grafana实现域名访问

1.Nginx安装及配置
因为服务器不能联网,所以采用离线安装的方式。以下4个依赖库分别安装,不详细描述安装过程。
1)依赖库安装
1. 安装 gcc 环境
$ sudo yum -y install gcc gcc-c++ # nginx 编译时依赖 gcc 环境
2. 安装 pcre
$ sudo yum -y install pcre pcre-devel # 让 nginx 支持重写功能
3. 安装 zlib
# zlib 库提供了很多压缩和解压缩的方式,nginx 使用 zlib 对 http 包内容进行 gzip 压缩
$ sudo yum -y install zlib zlib-devel
4. 安装 openssl
# 安全套接字层密码库,用于通信加密
$ sudo yum -y install openssl openssl-devel
以上安装完成后,进行 nginx 安装。
2)nginx 源码包安装
将准备好的 nginx-1.11.5.tar.gz 包,拷贝至 /usr/local/nginx 目录下(一般习惯在此目录下进行安装)进行解压缩。
源码包下载地址:nginx.org/en/download…
$ sudo tar -zxvf  nginx-1.11.5.tar.gz # 解压缩
在完成解压缩后,进入 nginx-1.11.5 目录进行源码编译安装。
$  cd nginx-1.11.5
//如果nginx make时出现pcre ...not found,openssl ...not found等报错
//以下命令 指定nginx依赖的pcre源码安装的路径、openssl源码安装的路径
./configure --prefix=/usr/local/nginx --with-pcre=/gcc/pcre-8.40 --with-openssl=/gcc/openssl-1.0.2k --with-http_ssl_module
进行源码编译并安装 nginx
$ make # 编译
$ make install # 安装
启动服务
$ /usr/local/nginx/sbin/nginx
重新加载服务
$ /usr/local/nginx/sbin/nginx -s reload
停止服务
$ /usr/local/nginx/sbin/nginx -s stop
查看 nginx 服务进程
$ ps -ef | grep nginx # 查看服务进程
//如果nginx make时出现pcre ...not found,openssl ...not found等报错
//以下命令 指定nginx依赖的pcre源码安装的路径、openssl源码安装的路径
./configure --prefix=/usr/local/nginx --with-pcre=/gcc/pcre-8.40 --with-openssl=/gcc/openssl-1.0.2k --with-http_ssl_module
2.Nginx配置
server {
        listen       443 ssl;    #设置nginx监听443端口
        server_name  display.hbas.rdc;    #配置访问的域名
        ssl_certificate /grafana/display.hbas.rdc.crt;    #配置证书
        ssl_certificate_key /grafana/display.hbas.rdc.key;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }
        location /grafana/ {
            root html;
            index index.html index.htm;
            proxy_pass http://172.16.20.83.190:3000;    #若浏览器访问https://tms_display.hbas.rdc:443/grafana,那么转为访问http://172.16.20.83.190:3000路径
            proxy_redirect default;
            proxy_max_temp_file_size 0k;
            proxy_connect_timeout 30;
            proxy_send_timeout 60;
            proxy_read_timeout 60;
            proxy_next_upstream error timeout invalid_header http_502;
            proxy_set_header Host display.hbas.rdc;    #该行必须配置,否则grafana中不能正常连接数据库。报错信息:orign not allowed!
        }
    }
3.grafana配置
[server]
# Protocol (http, https, h2, socket)
;protocol = https
;cert_file = /grafana/display.hbas.rdc.crt
;cert_key = /grafana/display.hbas.rdc.key
# The http port  to use
;http_port = 3000
# The public facing domain name used to access grafana from a browser
domain = display.hbas.rdc
# Redirect to correct domain if host header does not match domain
# Prevents DNS rebinding attacks
enforce_domain = false
# The full public facing url you use in browser, used for redirects and emails
# If you use reverse proxy and sub path specify full url (with sub path)
;root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana
root_url = https://display.hbas.rdc:443/grafana/
# Serve Grafana from subpath specified in `root_url` setting. By default it is set to `false` for compatibility reasons.
serve_from_sub_path = true
# https certs & key file
;cert_file = /grafana/display.hbas.rdc.crt
;cert_key = /grafana/display.hbas.rdc.key

你可能感兴趣的:(nginx,grafana,运维)