Apache 虛擬主機無法在 Ubuntu 14.04 LTS 上執行
我一直在使用本教程在我的 Ubuntu 電腦上設置 Apache 虛擬主機。我已經創建了一個
no-ip domain
我將用作我的虛擬主機的主機名。我已經按照教程的每個步驟進行操作,但它不起作用。這是虛擬主機文件,其名稱為crm2plus.ddns.net.conf
:<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@crm2plus.ddns.net ServerName crm2plus.ddns.net ServerAlias crm2plus.ddns.net DocumentRoot /var/www/crm2plus.ddns.net/public_html # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www> Options Indexes FollowSymLinks MultiViews AllowOverride All Order Allow,Deny Allow from all </Directory> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
我還在本地主機文件中添加了 ip 和域名對,它的外觀如下:
23.253.21.201 shhasan.ddns.net 127.0.1.1 Ubuntu-Dev 127.0.0.1 localhost 99.250.71.177 crm2plus.ddns.net # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters
crm2plus.ddns.net
當我通過 chrome導航到時,我得到了web page not available page
.shhasan.ddns.net
工作正常。當我ssh-keygen -H -F crm2plus.ddns.net
在終端中輸入時,什麼都沒有顯示,但是當我輸入時ssh-keygen -H -F shhasan.ddns.net
,顯示的是:# Host shhasan.ddns.net found: line 14 type RSA
後面是 RSA 密鑰。
我還查看了 Apache 錯誤和訪問日誌。錯誤日誌中有很多重複這樣的程式碼行:
[Fri Nov 14 17:44:50.304782 2014] [mpm_prefork:notice] [pid 21927] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.5 configured -- resuming normal operations [Fri Nov 14 17:44:50.304801 2014] [core:notice] [pid 21927] AH00094: Command line: '/usr/sbin/apache2' [Fri Nov 14 17:44:54.979832 2014] [mpm_prefork:notice] [pid 21927] AH00169: caught SIGTERM, shutting down
我搜尋了
caught SIGTERM, shutting down
一下,發現這是正常操作的一部分。我不知道我要去哪裡錯了。它以前適用於,shhasan.ddns.net
但不適用於crm2plus.ddns.net
.非常感謝所有幫助和建議。
更新:
developer@Ubuntu-Dev:/etc/apache2$ ls apache2.conf apache2.conf.dpkg-dist conf-enabled httpd.conf magic mods-enabled ports.conf~ sites-enabled apache2.conf~ conf-available envvars httpd.conf~ mods-available ports.conf sites-available
developer@Ubuntu-Dev:/etc/apache2/sites-available$ ls 000-default.conf 000-default.conf~ 000-default.conf.dpkg-dist crm2plus.ddns.net.conf crm2plus.ddns.net.conf~ default.save default-ssl.conf shhasan.ddns.net.conf
developer@Ubuntu-Dev:/etc/apache2/sites-enabled$ ls crm2plus.ddns.net.conf shhasan.ddns.net.conf
apache2.conf
縮短版:Include /etc/phpmyadmin/apache.conf ServerName localhost Mutex file:${APACHE_LOCK_DIR} default PidFile ${APACHE_PID_FILE} Timeout 300 KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeout 5 User ${APACHE_RUN_USER} Group ${APACHE_RUN_GROUP} HostnameLookups Off ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn IncludeOptional mods-enabled/*.load IncludeOptional mods-enabled/*.conf Include ports.conf <Directory /> Options FollowSymLinks AllowOverride All # Order deny,allow # Deny from all </Directory> <Directory /usr/share> AllowOverride None Require all granted </Directory> <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> #<Directory /srv/> # Options Indexes FollowSymLinks # AllowOverride None # Require all granted #</Directory> AccessFileName .htaccess <FilesMatch "^\.ht"> Require all denied </FilesMatch> LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %O" common LogFormat "%{Referer}i -> %U" referer LogFormat "%{User-agent}i" agent IncludeOptional conf-enabled/*.conf IncludeOptional sites-enabled/*.conf
/etc/phpmyadmin/apache.conf
文件:# phpMyAdmin default Apache configuration Alias /phpmyadmin /usr/share/phpmyadmin <Directory /usr/share/phpmyadmin> Options FollowSymLinks DirectoryIndex index.php <IfModule mod_php5.c> AddType application/x-httpd-php .php php_flag magic_quotes_gpc Off php_flag track_vars On php_flag register_globals Off php_admin_flag allow_url_fopen Off php_value include_path . php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/javascript/ </IfModule> </Directory> # Authorize for setup <Directory /usr/share/phpmyadmin/setup> <IfModule mod_authn_file.c> AuthType Basic AuthName "phpMyAdmin Setup" AuthUserFile /etc/phpmyadmin/htpasswd.setup </IfModule> Require valid-user </Directory> # Disallow web access to directories that don't need it <Directory /usr/share/phpmyadmin/libraries> Order Deny,Allow Deny from All </Directory> <Directory /usr/share/phpmyadmin/setup/lib> Order Deny,Allow Deny from All </Directory>
RiggsFolly 對 stackoverflow 的回答中虛擬主機定義的略微編輯版本適用於
crm2plus.ddns.net
<VirtualHost *:80> ServerName crm2plus.ddns.net ServerAlias crm2plus.ddns.net ServerRoot /var/www/crm2plus.ddns.net/ DocumentRoot /var/www/crm2plus.ddns.net/public_html <Directory "/var/www/crm2plus.ddns.net/public_html"> Options +Indexes +FollowSymLinks Order allow,deny Allow from all AllowOverride All </Directory> # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn ErrorLog ${APACHE_LOG_DIR}/crm2plus.ddns.net_error.log CustomLog ${APACHE_LOG_DIR}/crm2plus.ddns.net_access.log combined </VirtualHost>
看起來第二個 .conf 文件尚未載入。這可以通過
Include path/to/conf_files/*.conf
在 conf/apache2.conf 中包含並重新啟動 apache 來完成。請注意,訪問
crm2plus.ddns.net
應記錄在訪問日誌中。否則存在配置錯誤。VirtualHosts 可以配置如下。
- 確保兩個 FQDN 都指向 Apache2 伺服器的 IP。這可以通過 ping FQDN 來驗證。
- 實施小的更改並驗證每個步驟的結果。
這個基本範例已在 apache2.conf 中實現:
NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin webmaster@mydomain.com DocumentRoot /var/www/mydomain.com ServerName mydomain.com ErrorLog logs/mydomain.com-error_log CustomLog logs/mydomain.com-access_log common </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@myseconddomain.com DocumentRoot /var/www/myseconddomain.com ServerName myseconddomain.com ErrorLog logs/myseconddomain.com-error_log CustomLog logs/myseconddomain.com-access_log common </VirtualHost>
mkdir /var/www/mydomain.com && echo helloworld > /var/www/mydomain.com/index.html
mkdir /var/www/myseconddomain.com && echo helloworld2 > /var/www/myseconddomain.com/index.html
它可以工作,即一旦服務重新啟動,導航到
mydomain.com
顯示helloworld
和myseconddomain.com
結果。helloworld2
建議是從頭開始,實現兩個基本的 VirtualHost,以確保基礎工作正常。一旦這已經實施,可以進行其他更改。