分析Apache 與linux系統中配置

來源:互聯網
上載者:User

1.備份Apache服務的主設定檔

  [root@KCentOS5C ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.backup

  2.linux系統中配置Apache服務的主設定檔

  [root@KCentOS5C ~]# vi /etc/httpd/conf/httpd.conf

  這裡主要改動以下這些參數:

  ServerName *:80

  配置Apache的伺服器名,如果有網域名稱的話請填寫正確的伺服器名。

  Include conf.d/*.conf (/etc/httpd/conf.d)

  確認Apache擴充設定檔的存放路徑。

  3.查看Nagios網頁配置模板檔案

  [root@KCentOS5C ~]# less nagios-2.9/sample-config/httpd.conf

  # SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER

  # Last Modified: 11-26-2005

  #

  # This file contains examples of entries that need

  # to be incorporated into your Apache web server

  # configuration file. Customize the paths, etc. as

  # needed to fit your system.

  #setting for nagios

  ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" ###設定了Nagios的CGI執行目錄對應的系統路徑。

  # SSLRequireSSL

  Options ExecCGI

  AllowOverride None

  Order allow,deny

  Allow from all

  # Order deny,allow

  # Deny from all

  # Allow from 127.0.0.1

  AuthName "Nagios Access"

  AuthType Basic

  AuthUserFile /usr/local/nagios/etc/htpasswd.user ###這裡指定了訪問使用者帳戶庫檔案。

  Require valid-user

  Alias /nagios "/usr/local/nagios/share" ###設定了Nagios的網頁URL對應的系統路徑。

  # SSLRequireSSL

  Options None

  AllowOverride None

  Order allow,deny

  Allow from all

  # Order deny,allow

  # Deny from all

  # Allow from 127.0.0.1

  AuthName "Nagios Access"

  AuthType Basic

  AuthUserFile /usr/local/nagios/etc/htpasswd.user ###這裡指定了訪問使用者帳戶庫檔案

  Require valid-user

  {######將#setting for nagios --這一段加到/usr/local/apache/conf/httpd.conf的末尾。

  用/usr/local/apache/bin/apachctl configtest 檢測配置 --help查看##########}

  基本上這個檔案可以直接使用。根據這個設定檔中指定的AuthUserFile項,它指定的是通過Apache訪問Nagios的合法使用者的帳戶名稱單庫檔案,需要使用htpasswd命令對這個名單庫進行使用者的添加。而預設安裝環境下在/usr/local/nagios/etc/目錄下是沒有htpasswd.user這個檔案的,所以需要手動添加。請特別注意,用root身份建立的htpasswd.user檔案的許可權問題,應該在建立該檔案完畢後立即更改為nagios使用者nagios組的所有權,並且要增加Nagios同組使用者讀寫權限。

  4.整合Nagios網頁設定檔到Apache中

  將Nagios網頁設定檔作為Apache的擴充設定檔複製改名到Apache的擴充設定檔目錄/etc/httpd/conf.d/目錄下

  [root@KCentOS5C ~]# cp nagios-2.9/sample-config/httpd.conf /etc/httpd/conf.d/nagios-httpd.conf

  5.建立Nagios的網頁訪問使用者帳戶檔案(這裡必須要與Nagios網頁設定檔當中AuthUserFile指定的路徑檔案名稱一致)

  [root@KCentOS5C ~]# touch /usr/local/nagios/etc/htpasswd.user

  6.更改Nagios網頁訪問使用者帳戶檔案的屬主

  [root@KCentOS5C ~]# chown nagios.nagios /usr/local/nagios/etc/htpasswd.user

  7.對Nagios網頁訪問使用者帳戶檔案增加同群組成員讀寫權限(這主要是賦給apache這個系統使用者)

  [root@KCentOS5C ~]# chmod g+wr /usr/local/nagios/etc/htpasswd.user

  8.察看Nagios網頁訪問使用者帳戶檔案的屬性資訊

  [root@KCentOS5C ~]# ll /usr/local/nagios/etc/htpasswd.user

  -rw-rw-r-- 1 nagios nagios 0 Oct 5 14:05 /usr/local/nagios/etc/htpasswd.user

  9.添加htpasswd.user使用者

  我添加了一個kanecruise使用者,口令是123456。

  [root@KCentOS5C ~]# htpasswd -m /usr/local/nagios/etc/htpasswd.user kanecruise

  New password: 123456

  Re-type new password: 123456

  Adding password for user kanecruise

  10.查看htpasswd的使用方法,這裡我就解釋一些比較重要和常用的。

  [root@KCentOS5C ~]# htpasswd

  Usage:

  htpasswd [-cmdpsD] passwordfile username

  htpasswd -b[cmdpsD] passwordfile username password

  htpasswd -n[mdps] username

  htpasswd -nb[mdps] username password

  ◆-c Create a new file.

  建立新的帳戶庫檔案。

  ◆-n Don't update file; display results on stdout.

  ◆-m Force MD5 encryption of the password.

  添加一個MD5口令加密的新使用者。

  ◆-d Force CRYPT encryption of the password (default).

  ◆-p Do not encrypt the password (plaintext).

  添加一個口令不加密的新使用者。

  ◆-s Force SHA encryption of the password.

  添加一個SHA口令加密的新使用者。

  ◆-b Use the password from the command line rather than prompting for it.

  ◆-D Delete the specified user.

  刪除一個指定的使用者

  On Windows, NetWare and TPF systems the '-m' flag is used by default.

  在Windows、NetWare以及TPF這些作業系統中“-m”參數(啟用MD5對口令加密)是預設使用的

  On all other systems, the '-p' flag will probably not work.

  在其他的所有作業系統中“-p”(不對口令啟用加密)參數將可能會引起失敗。

  11.檢查htpasswd帳戶檔案

  [root@KCentOS5C ~]# cat /usr/local/nagios/etc/htpasswd.user

  kanecruise:$apr1$Qwk9h/..$HaRakpabADGZL10dwPcrx1

  使用者添加正確,並且口令都以MD5的方式加密了。

  以上講解的是在linux系統中配置Apache服務。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.