Ubuntu 11.04는 apache2와 함께 설치되고 모든 관련 패키지가 설치되었습니다. 나는 대부분의 블로그를 시험해 보았고 Google 및 다른 포럼을 가장 친한 친구로 만들었지만이 문제를 해결할 수는 없습니다.
개발을 위해 로컬 시스템에 명명 된 가상 호스트를 설정해야합니다.
“vivek”디렉토리를 만들고 /var/www
기본 index.html을 복사하고 일부 요소를 편집했습니다.
다음과 같이 파일 vivek.com
을 추가했습니다 /etc/apache2/sites-available
.
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.vivek.com
DocumentRoot /var/www/vivek
# Other directives here
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/vivek/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</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 ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
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>
</VirtualHost>
즉, 다음 줄을 추가했습니다
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.vivek.com
DocumentRoot /var/www/vivek
# Other directives here
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/vivek/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
“사이트 사용 가능”폴더에 이미 존재하는 기본 파일로 (편집하기 전에 기본 파일 백업을 수행함)
/ etc / hosts에있는 hosts 파일에 이것을 추가했습니다.
127.0.0.1 localhost
127.0.1.1 vivek-PC
127.0.0.1 www.vivek.com
오류없이 다음 작업을 수행했습니다.
root@vivek-PC:~# a2ensite vivek.com
Enabling site vivek.com.
Run '/etc/init.d/apache2 reload' to activate new configuration!
root@vivek-PC:~# /etc/init.d/apache2 reload
* Reloading web server config apache2
내가 입력했을 때 www.vivek.com
기본 index.html을 입력 /var/www
했지만 편집 된 / var / www / vivek 폴더에는 없습니다.
나중에 index.html을 편집 /var/www
했지만 여전히 동일한 index.html을 얻었습니다 (기본 편집 전). 모든 index.html이 편집되었지만 Apache는 요청할 때 계속 나타나는 숨겨진 파일이있는 것 같습니다.www.vivek.com
그리고 아이러니 한 것은 다시 시작한 후-Apache가 제대로 나타 났지만 내 사이트 www.vivek.com
는 나타나지 않았다 – 심지어 index.html이 숨겨져 있음에도 불구하고 .. 이제 브라우저에 “연결할 수 없습니다” “
도와주십시오. 나는 성공적인 결과없이 일주일 이래로 이것을 설정하려고 노력했습니다.
답변
나중에 / var / www에서 index.html을 편집했지만 여전히 동일한 index.html을 얻었습니다 (기본 편집 전). 모든 index.html이 편집되었지만 Apache는 www.vivek.com을 요청할 때 계속 표시되는 숨겨진 항목이있는 것 같습니다.
이것을 읽으면 캐시 된 파일을보고 있다고 생각합니다. 대신 누르는 F5또는 새로 고침 버튼을 눌렀을, 눌러 새로 고침에 캐시를 건너 뛰 Ctrl+를 F5.
또는 명령 줄 프로그램을 사용하십시오 curl
(기본적으로 설치되지 않음). 사용법 예 :
$ curl -i http://localhost/
HTTP/1.1 200 OK
Date: Sat, 02 Jul 2011 00:42:01 GMT
Server: Apache/2.2.17 (Ubuntu)
Last-Modified: Fri, 01 Jul 2011 04:12:49 GMT
ETag: "4507-b1-4a6fa3b114149"
Accept-Ranges: bytes
Content-Length: 177
Vary: Accept-Encoding
Content-Type: text/html
<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
참고 사항 : 깨끗한 아파치 설치에서 다음을 수행했습니다.
- 첫 번째 구성 파일을 추가하십시오
/etc/apache2/sites-available/vivek.com
- (
/etc/apache2/sites-available/default
손대지 않고 ) - 운영
sudo a2ensite vivek.com
- 운영
sudo /etc/init.d/apache reload
당신과 같은 메시지를받습니다. 그러나 서버를 시작하지 못했습니다. 서버 사용을 중지하고을 사용하여 sudo /etc/init.d/apache2 stop
다시 시작하면 sudo /etc/init.d/apache2 start
전혀 시작되지 않았습니다. 오류 로그를 보면 /var/log/apache2/error.log
몇 가지 오류가 발견되었습니다.
[Sat Jul 02 00:48:09 2011] [notice] Graceful restart requested, doing restart
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Sat Jul 02 00:48:09 2011] [warn] NameVirtualHost *:80 has no VirtualHosts
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
따라서 포트 80이 사용중인 것 같습니다. 그러나 Apache가 아직 시작되지 않은 경우을 실행하여 포트 80에서 아무것도 수신하지 않는 것을 확인할 수 있습니다 sudo netstat -tpln
. 구성을 검토 한 후 Listen 80
구성 파일에서 행 을 제거해야 한다고 결론을 내 렸습니다 /etc/apache2/sites-available/vivek.com
. 그 후 서버를 다시 시작 curl
하고을 사용 하여 서버가 요청에 올바르게 응답하고 있음을 확인했습니다.
KISS , 두 번째 호스트 블록은에서 다룹니다 /etc/apache2/sites-available/default
. 다음 구성 파일은 다음과 /etc/apache2/sites-available/vivek.com
같습니다.
<VirtualHost *:80>
ServerName www.vivek.com
DocumentRoot /var/www/vivek
# Other directives here
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/vivek/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
답변
이것을 간단하게 만드는 스크립트가 있습니다-https: //github.com/RoverWire/virtualhost
이것은 결국 주어진 답변에 의해 설명 된 것과 똑같은 얇은 일을하지만 단 하나의 명령으로 수행합니다. –
sudo virtualhost create mysite.local my_site
또한 생성 한 호스트를 삭제할 수 있습니다
sudo virtualhost delete mysite.local my_site
“my_dir”은 / var / www 이후에 시작한다고 가정합니다.
따라서 사이트 폴더가 / var / www / my_site에 있다면
이것을 실행해야합니다 (/ var / www없이 디렉토리 경로를 전달하십시오)-
sudo virtualhost create mysite.local my_site
스크립트 파일을 수정하고 기본 경로 “/ var / www”를 제거하여 사이트 디렉토리에 대한 절대 경로를 전달할 수도 있습니다.