在xampp中使用域名而不是localhost

2024-04-12php开发问题
10

本文介绍了在xampp中使用域名而不是localhost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我的问题可能很愚蠢,但老实说,我搜索了很多并获得了成功但并不完整.

My question may be stupid, But honestly I searched a lot and got success but not complete.

我在 Windows 8 中使用 xampp.

I use xampp with windows 8.

我的主机文件如下所示.

My host file looks as follows.

    127.0.0.1   localhost
    127.0.0.1   www.mysite.com

我的 httpd-vhosts.config 如下所示.

My httpd-vhosts.config looks as follows.

    NameVirtualHost 127.0.0.1
    <VirtualHost 127.0.0.1>
        DocumentRoot "C:/xampp/htdocs"
        ServerName localhost
    </VirtualHost>
    <VirtualHost 127.0.0.1>
        ServerName www.mysite.com
        ServerAlias mysite.com
        DocumentRoot "C:/xampp/htdocs/mysite"
    </VirtualHost>

这非常适合 http.但我启用了 ssl.

This works perfect for http. But I have enabled ssl.

当我输入 http://localhosthttps://localhost 时,两者都可以正常工作.

When I type http://localhost or https://localhost, Both work fine.

当我输入 http://mysite.com 就可以了,

When I type http://mysite.com it works,

当我输入 https://mysite.com 时,它被重定向为 https://mysite.com/xampp/ 并显示 xampp 的默认欢迎页面.

when I type https://mysite.com it is redirected as https://mysite.com/xampp/ and shows me default welcome page of xampp.

我尝试了以下事情.

1) 我没有使用 127.0.0.1,而是尝试在 httpd-vhosts.conf 中使用 *:80 但结果相同.

1) instead of using 127.0.0.1, I tried using *:80 in httpd-vhosts.conf But result was same.

2) 我没有使用 127.0.0.1,而是尝试在 httpd-vhosts.conf 中使用 *:443 但是在重新启动时 apache 无法再次启动.

2) instead of using 127.0.0.1, I tried using *:443 in httpd-vhosts.conf But at the time of restarting apache fails to start again.

请告诉我如何通过域名而不是使用 https 或 http 的 localhost 访问我的网站.

Please let me know how can I access my site through domain name instead of localhost with https or http.

推荐答案

我尝试了很多东西,但我想我错过了基本的编辑.

I tried many things, But I think I missed basic edit.

现在一切正常.

现在主机文件仍然与问题中提到的相同.我没有对其进行任何更改.

Now host file is still the same as mentioned in question. I did not make any changes to it.

我在 httpd-vhosts.config 中更改了端口,如下所示.

I changed port in httpd-vhosts.config as shows below.

NameVirtualHost *
    <VirtualHost *>
        DocumentRoot "C:/xampp/htdocs"
        ServerName localhost
    </VirtualHost>
    <VirtualHost *>
        ServerName www.mysite.com
        ServerAlias mysite.com
        DocumentRoot "C:/xampp/htdocs/mysite"
    </VirtualHost>

另外我错过的步骤是在 httpd-vhosts.config 的同一文件夹中编辑 httpd-ssl.config 文件.

Also the step I missed, was editing httpd-ssl.config file in same folder that of httpd-vhosts.config.

我刚刚在 http-ssl.config 文件的最后一行之前添加了以下行,即 </IfModule>

I just added following lines before last line of http-ssl.config file i.e. < /IfModule>

<VirtualHost _default_:443> 
    DocumentRoot "C:/xampp/htdocs/mysite" 
    ServerName www.mysite.com:443 
    ServerAlias mysite.com:443  
    SSLEngine on 
    SSLCertificateFile "conf/ssl.crt/server.crt" 
    SSLCertificateKeyFile "conf/ssl.key/server.key" 
</VirtualHost> 

感谢所有朋友在这方面为我提供了很多帮助,如果没有您的链接,我将永远无法发现我需要再编辑一个文件.

Thank You all friends for helping me lot on this, Without your links I would never ever be able to find out that I need to edit one more file.

这篇关于在xampp中使用域名而不是localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17