简体   繁体   中英

Apache disable localhost redirection

i got a problem with apache conf with Laragon.

so the case is :

i got 2 subdomain subdom1.mysite.com (DNS Record to IP 1.2.3.4) subdom2.mysite.com (DNS Record to IP 1.2.3.4) IP 1.2.3.4 is my VPS

everything went well, but i got a problem. when i access 'localhost' from my VPS, it keeps redirecting to subdom1.mysite.com and localhost/phpMyAdmin also redirected to subdom1.mysite.com/phpMyAdmin

here's my httpd.conf

Define APACHE_LOG_DIR "C:/mydir/logs"
Define APACHE_ROOT_WEB_DIR "C:/mydir/wwwroot"

ServerName localhost
DocumentRoot "C:/mydir/wwwroot"

<Directory "C:/mydir/wwwroot">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<VirtualHost *:80>
    ServerName subdom1.mysite.com
    ServerAlias subdom1.mysite.com
    DocumentRoot  ${APACHE_ROOT_WEB_DIR}\subdom1.mysite.com

    ErrorLog ${APACHE_LOG_DIR}/subdom1.mysite.com-error.log
    CustomLog ${APACHE_LOG_DIR}/subdom1.mysite.com-access.log combined
</VirtualHost>

<VirtualHost *:80>
    ServerName subdom2.mysite.com
    ServerAlias subdom2.mysite.com
    DocumentRoot ${APACHE_ROOT_WEB_DIR}\subdom2.mysite.com

    ErrorLog ${APACHE_LOG_DIR}/subdom2.mysite.com-error.log
    CustomLog ${APACHE_LOG_DIR}/subdom2.mysite.com-access.log combined
</VirtualHost>

my localhost keeps redirecting to first vHost. I've googled lot's of combination of directory, serverName etc. But no luck.

Your VirtualHost s are binding to all available interfaces. Because of how apache determines to which VHost should route a request, it's ending up in the first one defined.

You can either:

  • Bind your subdomains to the external ip only.
  • Create a VirtualHost for the main server using the loopback ip.
  • Create a VirtualHost with the _default_ address.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM