站長資訊網
        最全最豐富的資訊網站

        Zabbix替換默認Web服務器httpd為Nginx

        本身環境zabbix之前是采用的lamp環境rpm包去安裝zabbix的。現在要換成nginx做為web服務。

        替換思路 : zabbix的web服務是用php寫的,httpd 只是一個web服務器。有了替換思路我們就進行下一步,我們首先找到php程序存放的目錄。

        找到zabbix.conf并打開文件 /etc/httpd/conf.d/zabbix.conf,根據路徑來看不難判斷這個文件應該就是httpd配置文件,打開文件根據Directory可以判    斷/usr/share/zabbix為程序所在目錄。

        找到zabbix程序所在目錄后,我們就著手配置nginx就好了,進入nginx的配置目錄并打開 /etc/nginx/conf.d/default.conf文件(或者另外創建一個zabbix.conf 的文件)

        安裝好lnmp環境,nginx是基于php-fpm,rhel7.4只有php相關rpm包,但沒有php-fpm的rpm包,所以需要自己下載相應版本的php-fpm的rpm包并安裝,

        zabbix不想放在網站根目錄下,這樣不容易和網站應用混在一起,這樣zabbix的目錄就放在別處,在Apache里,有alias,比較方便,在Nginx下沒有虛擬目錄概念的,是用location配合alias使用,但使用alias標簽的目錄塊中不能使用rewrite的break。我先試了簡單的配置方式:

        編輯default.conf為下面的內容:

        一、采用別名配置方法一:

        # vi /etc/nginx/conf.d/default.conf
        server {
            listen      80;
            server_name  localhost;
            #charset koi8-r;
            #access_log  /var/log/nginx/host.access.log  main;
           
        采用別名zabbix方式:http://IP/zabbix,這樣去訪問,就不用nginx默認/目錄了
            location /zabbix {
                alias  /usr/share/zabbix;  #是zabbix前端的PHP文件所在目錄
                index  index.html index.htm index.php;
            }
           
           
            #設置下面幾個目錄 不允許外部訪問
            location ^~ /app {
                deny all;
            }
           
            location ^~ /conf {
                deny all;
            }
           
            location ^~ /local {
                deny all;
            }
           
            location ^~ /include {
                deny all;
            }
           
           
            #error_page  404              /404.html;
            # redirect server error pages to the static page /50x.html
            #
            error_page  500 502 503 504  /50x.html;
            location = /50x.html {
                root  /usr/share/nginx/html;
            }
           
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ .php$ {
            #    proxy_pass  http://127.0.0.1;
            #}
           
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
           
            # 配置nginx和php-fpm通信
            # 我們使用端口的形式來進行通訊
            # 前面注釋去掉并修改成你需要的
            location ~ ^/zabbix/.+.php$ {
                #fastcgi_split_path_info ^(.+.php)(/.+)$;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /usr/share$fastcgi_script_name;
                include        fastcgi_params;
            }
           
            # deny access to .htaccess files, if Apache’s document root
            # concurs with nginx’s one
            #
            #location ~ /.ht {
            #    deny  all;
            #}
        }

        配置好之后保存文件

        啟動服務:

        systemctl start php-fpm
        systemctl restart nginx
        systemctl restart zabbix-server zabbix-agent

        開機啟動:

        systemctl enable php-fpm
        systemctl enable zabbix-server zabbix-agent nginx

        二、采用別名配置方法二:

        # vi /etc/nginx/conf.d/default.conf
        server {
            listen      80;
            server_name  localhost;
            #charset koi8-r;
            #access_log  /var/log/nginx/host.access.log  main;
           
           
            location /zabbix {
                alias  /usr/share/zabbix;
                index  index.html index.htm index.php;
            }
           
            #設置下面幾個目錄 不允許外部訪問
            location ^~ /app {
                deny all;
            }
           
            location ^~ /conf {
                deny all;
            }
           
            location ^~ /local {
                deny all;
            }
           
            location ^~ /include {
                deny all;
            }
           
            #error_page  404              /404.html;
            # redirect server error pages to the static page /50x.html
            #
            error_page  500 502 503 504  /50x.html;
            location = /50x.html {
                root  /usr/share/nginx/html;
            }
           
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ .php$ {
            #    proxy_pass  http://127.0.0.1;
            #}
           
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            # 配置nginx和php-fpm通信
            # 我們使用端口的形式來進行通訊
            #此方法二原理應該是采用rewrite的方法,對于/zabbix/下php類型的的請求交給后端的FastCGI處理,
              #并且指定了php腳本的位置,這樣我們就可以配置zabbix了,配置如下:
            location ~ ^/zabbix/.+.php$ {
                root /usr/share;
                rewrite /zabbix/(.*.php?) /$1 break;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /usr/share/zabbix$fastcgi_script_name;
                include        fastcgi_params;
            }
           
            location ~ .*.(php|php5)?$ {
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
            }
           
            # deny access to .htaccess files, if Apache’s document root
            # concurs with nginx’s one
            #
            #location ~ /.ht {
            #    deny  all;
            #}
           
        }

        要注意的是:
        location ~ .*.(php|php5)?$ {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        include fcgi.conf;
        }

        這段,要放在location ~ ^/zabbix/.+.php$的后面,放在前面就有問題,這是和Nginx的location規則有關,具體看Nginx的文檔,
        另外,zabbix里要配置一下URI的絕對路徑,就可以了。

        三、訪問zabbix服務:http:/IP/zabbix

        Zabbix替換默認Web服務器httpd為Nginx

        到上面為止,我們就替換zabbix默認web服務器httpd為nginx。但是我們還沒有結束,是的,還沒有結束!!!

        我們登錄后可能會出現如下報錯,這個是需要設置php.ini參數date.timezone設置php的默認時區,設置好后點重試,即可打開首頁了

        Zabbix替換默認Web服務器httpd為Nginx

        當跳轉到首頁,右下角dashboard模塊下 Status of Zabbix 有幾個紅色的異常

        Zabbix替換默認Web服務器httpd為Nginx

        1、date.timezone => 沒有設置php的默認時區

        2、max_input_time 60

        3、max_execution_time 30

        4、post_max_size    8M   

        這四個是php配置問題,我們只需要編輯php.ini就好了

        #vi /etc/php.ini
        post_max_size = 16M
        max_input_time = 300
        max_execution_time = 300
        date.timezone = Asia/Shanghai

        到這里完成結束了。

        贊(0)
        分享到: 更多 (0)
        網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號
        主站蜘蛛池模板: 精品一区二区在线观看| 99精品在线免费| 国产高清在线精品一本大道国产| 欧洲精品码一区二区三区免费看| 久久线看观看精品香蕉国产| 日韩精品无码久久久久久| 精品久久久久久国产三级| 欧美国产亚洲精品高清不卡| 精品国产乱码一区二区三区| 一本久久精品一区二区| 精品国产福利盛宴在线观看| 亚洲国产精品第一区二区| 精品无码人妻一区二区三区| 日韩AV毛片精品久久久| 国产精品美女久久久免费| 精品三级在线观看| 99热亚洲色精品国产88| 欧美精品中文字幕亚洲专区| 一本久久a久久精品综合香蕉| 免费短视频软件精品一区二区 | 国内精品伊人久久久久影院对白| 国产精品欧美一区二区三区不卡 | 成人国产精品999视频| 精品一区二区三区在线成人| 亚洲精品成人久久久| 欧美成人精品一区二三区在线观看 | 久久久久久久亚洲精品| 国亚洲欧美日韩精品| 精品久久久久久无码人妻热| 国产网红主播无码精品| 国内精品久久久久久久影视麻豆 | 国产AⅤ精品一区二区三区久久| 中文字幕成人精品久久不卡| 香蕉久久夜色精品国产小说| 99在线观看视频免费精品9| 一本大道久久a久久精品综合| 66精品综合久久久久久久| 国产精品免费观看视频| 国产亚洲精品成人a v小说| 久久精品视频91| 最新国产精品拍自在线观看|