
我剛剛使用 Apache 在 Ubuntu 14 LTS 上安裝了 nagios,我透過 example.com/nagios3 造訪該站點,但我想使用虛擬主機來存取 nagios,例如 nagios.example.com。做這個的最好方式是什麼?
答案1
假設
- 標準 Apache2 伺服器是從 Ubuntu 儲存庫安裝的,預設安裝沒有進行任何更改
- Nagios 預設安裝在 /var/www/ 資料夾中,資料夾名稱為 nagios3
- Nagios.example.com 解析為有效的 IP 位址並且與 nagios 伺服器相同
使用 nagios 作為 nagios.example.com 的步驟 – 透過 SSH 連接到伺服器並執行以下命令
1. cd /etc/apache2/sites-available
2. sudo cp default nagios.example.com
3. sudo nano nagios.example.com
4它應該看起來像這樣 – 不要複製貼上此程式碼。只需添加我在第 4、5、6 和 11 行中提到的條目即可
NameVirtualHost *
<VirtualHost *>
ServerAdmin webmaster@localhost
ServerName nagios.example.com # Add this line
ServerAlias nagios # Add this line
DocumentRoot /var/www/nagios3 # Add nagios3 at the end of this line
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/nagios3/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
RedirectMatch ^/$ /apache2-default/
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
- ^ O(用於保存文件)
- ^ X(用於退出 nano 編輯器)
- sudo a2ensite nagios.example.com(用於啟用虛擬主機)
- sudo 服務 apache2 重新啟動
- 開啟瀏覽器並輸入http://nagios.example.com並且您應該能夠看到 nagios 登入頁面(確保可以從您用於存取 nagios 的電腦解析 nagios.example.com - 如果您無法在本機主機檔案中輸入條目)
希望這有幫助
問候