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

        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號
        主站蜘蛛池模板: 久久夜色精品国产亚洲| 99re66在线观看精品免费| 国产成人精品无码播放| 国产呦小j女精品视频| 97久久精品人妻人人搡人人玩| 香港三级精品三级在线专区 | 精品国产欧美一区二区三区成人| 国产免费伦精品一区二区三区| 99re热视频这里只精品| 在线观看亚洲精品国产| 精品精品国产欧美在线小说区 | 欧美精品中文字幕亚洲专区| 国产区精品福利在线观看精品| 精品国产一区二区三区久久| 久久国产精品77777| 亚洲精品动漫免费二区| 麻豆国内精品久久久久久| 97久视频精品视频在线老司机| 99久久精品毛片免费播放| 无码国内精品人妻少妇| 日韩精品人妻av一区二区三区| 国产精品人人做人人爽人人添| 66精品综合久久久久久久| 精品一区二区三区在线视频| 国产成人精品2021| 精品无码国产自产拍在线观看| 亚洲AV永久无码精品水牛影视| 亚洲国产综合精品一区在线播放 | 日韩精品一区二区三区四区| 国产精品美女久久久m| 亚洲AV无码精品色午夜在线观看| 亚洲国产精品日韩| 中文字幕精品亚洲无线码一区应用 | 孩交VIDEOS精品乱子| 无码精品视频一区二区三区| 中国国产精品| 少妇人妻偷人精品免费视频| 最新国产成人精品2024| 永久无码精品三区在线4| 亚洲国产精品VA在线观看麻豆| 伊人久久精品无码二区麻豆|