Nice programing

XAMPP에서 가상 호스트를 만드는 방법

nicepro 2020. 10. 29. 19:55
반응형

XAMPP에서 가상 호스트를 만드는 방법


이 질문이 여러 번 제기되고 있다고 확신하지만 문제가 발생하지 않습니다. Zend 프레임 워크를 구성하는 XAMPP를 사용하고 있습니다.

XAMPP이 실행되고 포트 808180 것은 내가 코드를 다음과 같이 그 I의 구성에 대한 가상 호스트를 사용할 필요가 일부 Windows 프로세스에 의해 점유되고있는 C:/xampp/apache/config/extra/httpd-vhosts.config(또는 C:/xampp/apache/conf/extra/httpd-vhosts.conf새로운 릴리스에서).

<VirtualHost *:80>
ServerName comm-app.local
DocumentRoot "C:/xampp/htdocs/CommunicationApp/public"
SetEnv APPLICATION_ENV "development"
    <Directory "C:/xampp/htdocs/CommunicationApp/public"
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>    

또한 호스트 파일을 업데이트하고 127.0.0.1 comm-app.local아파치를 다시 시작하려고 시도하지만 오류가 표시됩니다.

15:03:01  [Apache]  Error: Apache shutdown unexpectedly.
15:03:01  [Apache]  This may be due to a blocked port, missing dependencies, 
15:03:01  [Apache]  improper privileges, a crash, or a shutdown by another method.
15:03:01  [Apache]  Press the Logs button to view error logs and check
15:03:01  [Apache]  the Windows Event Viewer for more clues
15:03:01  [Apache]  If you need more help, copy and post this
15:03:01  [Apache]  entire log window on the forums

두 가지 오류가 있습니다.

<VirtualHost *:80> -> Fix to :8081, your POrt the server runs on
    ServerName comm-app.local
    DocumentRoot "C:/xampp/htdocs/CommunicationApp/public"
    SetEnv APPLICATION_ENV "development"
    <Directory "C:/xampp/htdocs/CommunicationApp/public" -> This is probably why it crashes, missing >
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
 -> MIssing close container: </VirtualHost> 

고정 버전 :

<VirtualHost *:8081>
    ServerName comm-app.local
    DocumentRoot "C:/xampp/htdocs/CommunicationApp/public"
    SetEnv APPLICATION_ENV "development"
    <Directory "C:/xampp/htdocs/CommunicationApp/public">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

한 가지 언급 할 사항 :

언제든지 다음 명령을 시도하고 실행할 수 있습니다.

service apache2 configtest

이것은 잘못된 구성을 받았을 때 알려주고 문제가 어디에 있는지 알려줄 수도 있습니다.

또한 라이브 시스템에서 사용할 수 없음을 방지하는 데 도움이됩니다.

service apache2 restart

종료되고 시작되지 않습니다.이 configtest는 미리 알고 있습니다. "죄송합니다.이 문제를 먼저 수정해야합니다."하지만 아파치 자체는 여전히 이전 구성으로 실행 중입니다. :)


1 단계) C : \ WINDOWS \ system32 \ drivers \ etc \ "hosts"파일 열기 :

127.0.0.1       localhost
127.0.0.1       test.com
127.0.0.1       example.com

2 단계) xampp \ apache \ conf \ extra \ httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot C:/xampp/htdocs/test/
    ServerName www.test.com
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot C:/xampp/htdocs/example/
    ServerName www.example.com
</VirtualHost>

3 단계) C : \ xampp \ apache \ conf \ httpd.conf. 끝에있는 보조 구성 섹션까지 아래로 스크롤하고 다음 섹션 (500 줄 주변)을 찾습니다. 이제 섹션이 다음과 같이 보이도록 두 번째 줄의 시작 부분에서 #을 제거합니다.

#Virtual hosts
Include conf/extra/httpd-vhosts.conf

4 단계) XAMPP를 다시 시작하고 이제 브라우저에서 실행합니다.

www.example.com or www.test.com

C : \ xampp \ apache \ conf \ extra \ httpd-vhosts.conf 파일의 끝에이 코드를 작성합니다.

DocumentRoot "D:/xampp/htdocs/foldername"
ServerName www.siteurl.com
ServerAlias www.siteurl.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common

가상 호스트 태그 사이.

System32 / Drivers / etc / hosts 파일을 편집하고 메모장을 관리자로 사용합니다.

파일 하단 추가

127.0.0.1    www.siteurl.com

이 코드를 C : \ xampp \ apache \ conf \ extra \ httpd-vhosts.conf에 추가하십시오.

<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName qa-staging.com
ServerAlias www.qa-staging.com
<Directory "c:/xampp/htdocs">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

이제 다음 파일에 가상 호스트 이름을 추가하십시오.

C:\Windows\System32\drivers\etc\hosts

127.0.0.1 qa-staging.com

이 코드를 호스트 파일에 저장할 수없는 경우 notpad를 마우스 오른쪽 버튼으로 클릭하고 관리자 권한으로 실행을 선택한 다음 사용자 지정 코드를 저장할 수 있습니다. 이제 XAMP를 다시 시작합니다.


포트를로 변경하면 8081다음 가상 호스트가 작동합니다.

<VirtualHost *:8081>
ServerName comm-app.local
DocumentRoot "C:/xampp/htdocs/CommunicationApp/public"
SetEnv APPLICATION_ENV "development"
    <Directory "C:/xampp/htdocs/CommunicationApp/public">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory> 
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "D:/projects/yourdirectry name"
    ServerName local.yourdomain.com
    <Directory "D:/projects/yourdirectry name">
        Require all granted 
    </Directory>
</VirtualHost>

Apache 구성 파일을 저장하십시오.

자세한 정보는 이것을 참조하십시오


Apache 가상 호스트 설명서 가상 호스트 (vhost)를 설정하면 다음과 같은 몇 가지 이점이 있습니다.

  • 가상 호스트는 URL을 더 깔끔하게 만듭니다. localhost / mysite 대 mysite.local.
  • 가상 호스트는 권한을 더 쉽게 만듭니다. 로컬 네트워크의 단일 가상 호스트에 대한 액세스를 제한하는 대신 로컬 네트워크의 모든 사이트에 대한 액세스를 허용합니다.
  • 일부 응용 프로그램에는 "."가 필요합니다. URL (ahem Magento)에서. Windows 호스트 파일을 편집하여 localhost.com/mysite를 설정할 수 있지만 가상 호스트를 만드는 것이 더 나은 솔루션입니다.

VirtualHost 지시문 특정 호스트 이름 또는 IP 주소에만 적용되는 지시문을 포함합니다.

위치 지시문 포함 된 지시문을 일치하는 URL에만 적용합니다.

구성 파일 변경 -D:\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin localhost
    DocumentRoot "D:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost localhost:80>
  ServerAdmin webmaster@host.example.com
  DocumentRoot "/www/docs/host.example.com"
  #DocumentRoot "D:\xampp\htdocs\phpPages"
  ServerName host.example.com
  ErrorLog "logs/host.example.com-error_log"
  TransferLog "logs/host.example.com-access_log"
</VirtualHost>

# To get view of PHP application in the Browser.
<VirtualHost *:80>
    ServerAdmin postmaster@dummy-host.localhost
    DocumentRoot "D:\xampp\htdocs\app1"
    ServerName app1.yash.com
    ServerAlias app1.yash.com
    ErrorLog "logs/app1.yash.com-error.log"
    CustomLog "logs/app1.yash.com-access.log" combined

    # App1 communication proxy call to Java War applications from XAMP
    <Location /ServletApp1>
            ProxyPass  http://app1.yashJava.com:8080/ServletApp1
            ProxyPassReverse  http://app1.yashJava.com:8080/ServletApp1
            Order Allow,Deny
            Allow from all
    </Location>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin postmaster@infotreesolutions.com
    DocumentRoot "D:\xampp\htdocs\app2"
    ServerName app2.yash.com
    ErrorLog "logs/app2.yash.com-error.log"
    CustomLog "logs/app2.yash.com-access.log" combined

    # App1 communication proxy call to Java War applications from XAMP
    <Location /ServletApp2>
            ProxyPass  http://app1.yashJava.com:8080/ServletApp2
            ProxyPassReverse  http://app1.yashJava.com:8080/ServletApp2
            Order Allow,Deny
            Allow from all
    </Location>
</VirtualHost>

Windows 호스트 파일 업데이트«다음에있는 Windows 호스트 파일 열기 C:\Windows\System32\drivers\etc\hosts.

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost

127.0.0.1       test.com
127.0.0.1       example.com
127.0.0.1       myssl.yash.com

D:\xampp\apache\conf\httpd.conf, [httpd-ssl.conf](http://httpd.apache.org/docs/2.2/mod/mod_ssl.html)

# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost> directive.
# Listen 0.0.0.0:80 | [::]:80
Listen 80

LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule speling_module modules/mod_speling.so

# ServerAdmin: Your address, where problems with the server should be e-mailed.
# This address appears on some server-generated pages, such as error documents.
#  e.g. admin@your-domain.com
ServerAdmin postmaster@localhost
ServerName localhost:80
DocumentRoot "D:/xampp/htdocs"

<Directory "D:/xampp/htdocs">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
</Directory>

# Virtual hosts
Include "conf/extra/httpd-vhosts.conf"

# ===== httpd-ssl.conf - SSL Virtual Host Context =====
# Note: Configurations that use IPv6 but not IPv4-mapped addresses need two
#       Listen directives: "Listen [::]:443" and "Listen 0.0.0.0:443"
Listen 443
## SSL Virtual Host Context
<VirtualHost _default_:443>
    DocumentRoot "D:\xampp\htdocs\projectFolderSSL"
    ServerName myssl.yash.com:443
    ServerAlias myssl.yash.com:443

    ServerAdmin webmaster@localhost
    ErrorLog "logs/error.log"
    <IfModule log_config_module>
        CustomLog "logs/access.log" combined
    </IfModule>

    ## Redirecting URL from Web server to Application server over different machine.
    # myssl.yash.com:443/ServletWebApp
    <Location /path>
        ProxyPass  http://java.yash2.com:8444/ServletWebApp
        ProxyPassReverse  http://java.yash2.com:8444/ServletWebApp
        Order Allow,Deny
        Allow from all
    </Location>

    #SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateFile "D:\SSL_Vendor\yash.crt"

    #SSLCertificateKeyFile "conf/ssl.key/server.key"
    SSLCertificateKeyFile "D:\SSL_Vendor\private-key.key"

    #SSLCertificateChainFile "conf/ssl.crt/server-ca.crt"
    SSLCertificateChainFile "D:\SSL_Vendor\intermediate.crt"
</VirtualHost>
# ===== httpd-ssl.conf - SSL Virtual Host Context =====

@보다


다음 구성을 사용하여 수정했습니다.

 Listen 85
 <VirtualHost *:85>
           DocumentRoot "C:/xampp/htdocs/LaraBlog/public"
           <Directory "C:/xampp/htdocs/CommunicationApp/public">
           DirectoryIndex index.php
           AllowOverride All
           Order allow,deny
           Allow from all
           </Directory>
 </VirtualHost>

Your disk drive : \ xampp \ apache \ conf \ extra \ httpd-vhosts.conf에는 예제가 있으며 구성으로 편집 할 수 있습니다.

 ##<VirtualHost *:80>
 ##ServerAdmin webmaster@dummy-host.example.com
 ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
 ##ServerName dummy-host.example.com
 ##ServerAlias www.dummy-host.example.com
 ##ErrorLog "logs/dummy-host.example.com-error.log"
 ##CustomLog "logs/dummy-host.example.com-access.log" common
 ##</VirtualHost>

예를 들면 다음과 같습니다. 예를 들어 store.local 프로젝트에서 보여줄 것처럼 포트 80에서 phpmyadmin과 다른 프로젝트를 동시에 실행할 수 있도록 localhost 자체에 VirtualHost를 추가하는 것을 잊지 마십시오 .

<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@store.local
DocumentRoot "c:/xampp/htdocs/store.local/public"
ServerName www.store.local
ServerAlias store.local
<Directory C:/xampp/htdocs/store.local>
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

그런 다음 위에서 언급했듯이 파일 하단에 C : \ windows \ system32 \ drivers \ hosts를 추가해야 합니다.

127.0.0.1    store.local
127.0.0.1    www.store.local

Apache를 다시 시작하고 브라우저에서 시도하십시오.

store.local or www.store.local

아마도 처음에 다음과 같이 추가해야합니다.

http://store.local or http://www.store.local

다른 포트를 사용하려면 VirtualHost 앞에 다음을 추가해야합니다.

Listen 8081 or another which you prefer

그런 다음 다음과 같이 VirtualHost에 대한 포트를 사용하십시오.

<VirtualHost *:8081>
ServerAdmin webmaster@store.local
DocumentRoot "c:/xampp/htdocs/store.local/public"
ServerName store.local
ServerAlias www.store.local
<Directory C:/xampp/htdocs/store.local>
    AllowOverride All
    Require all granted
</Directory>

그런 다음 Apache를 다시 시작하고 브라우저에서 시도하십시오.

store.local:8081 or www.store.local:8081

포트를 추가 한 프로젝트 만이 포트에서 실행됩니다. 예를 들어 다른 프로젝트와 phpmyadmin은 여전히 ​​포트 80에서 실행됩니다.


파티에 조금 늦었지만 터미널을 통해 VirtualHost를 생성하는 Mac 용 작은 bash 스크립트를 작성했습니다.

#!/bin/bash

echo "Welcome to the VirtualHostCreator! Press <RETURN> to continue."

read

echo "Enter the name the VirtualHost you would like to create. No spaces or dashes, please."

read hostname

echo "Enter the document root of the VirtualHost."

read doc_root

echo "Creating VirtualHost \"$hostname\". You may be prompted for your password."

hosts_file="/etc/hosts"
vhosts_file="/Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf"
restart_command="sudo /Applications/XAMPP/xamppfiles/xampp restart"

cat >> $vhosts_file << EndOfMessage
<VirtualHost ${hostname}>
    ServerName ${hostname}
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/${doc_root}"
</VirtualHost>
EndOfMessage

sudo sh -c "echo \"127.0.0.1       $hostname\" >> $hosts_file"

$restart_command

몇 가지 개선 할 수 있고 가상 호스트 (서버 이름 및 문서 루트)에 필요한 두 가지 옵션 만 있지만 모든 파일을 열고 편집하는 것보다 훨씬 빠르고 효율적으로 작업을 수행합니다. 수동으로 수행하고 나중에 XAMPP를 자동으로 다시 시작합니다.

여기에서는 XAMPP의 기본 설치 위치가 있으며 모두 변경할 수 있다고 가정합니다.


1 단계) "C : \ Windows \ System32 \ drivers \ etc"에서 호스트 파일 열기

더하다

127.0.0.1  vipsnum.mk

2 단계) "C : \ xampp \ apache \ conf \ extra"에서 httpd-vhosts.conf 파일을 엽니 다.

더하다

<VirtualHost vipsnum.mk:80>
    ServerName vipsnum.mk
    DocumentRoot "C:/xampp/htdocs/vipnum/"
    SetEnv APPLICATION_ENV "development"
    <Directory "C:/xampp/htdocs/vipnum/">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost> 

1. C:\xampp\apache\conf\https.conf
Virtual hosts
Include conf/extra/httpd-vhosts.conf


2. C:\Windows\System32\drivers\etc\hosts
127.0.0.1       localhost
127.0.0.1       helpdesk.local


3. C:\xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/helpdesk/public"
    ServerName helpdesk.local
</VirtualHost>


Now, Restart Apache and go through the link. 
URL : http://helpdesk.local

Problem with xampp in my case is when specifying a different folder other than htdocs are used, especially with multiple domains and dedicated folders. This is because httpd-ssl.conf is also referencing <VirtualHost>.

To do this rem out the entire <VirtualHost> entry under httpd-ssl.conf

From there, any setting you do in your httpd-vhosts.conf will update as expected both http and https references.


I have added below configuration to the httpd.conf and restarted the lampp service and it started working. Thanks to all the above posts, which helped me to resolve issues one by one.

Listen 8080
<VirtualHost *:8080>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/opt/lampp/docs/dummy-host2.example.com"
    ServerName localhost:8080
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
    <Directory "/opt/lampp/docs/dummy-host2.example.com">
        Require all granted 
    </Directory>
</VirtualHost>

Simple, You can see the below template and use it accordingly. Its very common to create a virtual host and very simple. Surely below template will work.

<VirtualHost *:8081>
DocumentRoot "C:/xampp/htdocs/testsite"
ServerName testsite.loc
ServerAlias www.testsite.loc
<Directory "c:/xampp/htdocs/testsite">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Also for more reference about virtual host please visit this site. http://www.thegeekstuff.com/2011/07/apache-virtual-host

Thanks,

참고URL : https://stackoverflow.com/questions/27268205/how-to-create-virtual-host-on-xampp

반응형