我正在尝试为mampstack(不是MAMP)设置一个虚拟主机。这是我到目前为止所做的:
在我的 httpd.conf 文件中,我已经检查过
Listen 8080
这是正确的(我正在侦听端口 8080,而不是 80)。
然后我取消了评论:Include conf/extra/httpd-vhosts.conf
在我的httpd.conf
文件中
在我的主机文件中,我添加了以下内容:127.0.0.1 mext-pst.local
.
在httpd-vhosts.conf
中,我添加了:
NameVirtualHost *:8080
<VirtualHost *:8080>
DocumentRoot "/Applications/mampstack-5.4.20-0/apache2/htdocs"
ServerName 127.0.0.1
ServerAlias localhost
SetEnv APPLICATION_ENV development
SetEnv APPLICATION_DOMAIN localhost
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/Applications/mampstack-5.4.20-0/apache2/htdocs/mext-pst-dashboard/web"
ServerName mext-pst.local
ServerAlias mext-pst.local
SetEnv APPLICATION_ENV development
SetEnv APPLICATION_DOMAIN mext-pst.local
RewriteEngine on
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^ http://%{HTTP_HOST}:8080%{REQUEST_URI} [P]
</VirtualHost>
现在,当我转到http://mext-pst.local/
时,我只是收到浏览器的错误,他无法与页面连接......
当我转到http://mext-pst.local:8080/
时,出现以下错误:
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /index.php.
Reason: DNS lookup failure for: mext-pst.local:8080
当我去http://mext-pst.local:8080/index.php
它有效时...
将 8080 更改为 80 这是默认值。但是,如果您希望您的网站在 8080 上运行,那么您必须使用它。另一种解决方案可能是重写 URL,即当您的服务器获得 url 时,它会用端口号 (8080) 重写它。
首先,将 Listen 8080 更改为 Listen 80,因为您希望应用程序只能使用 http 访问。在您的 http-vhost.conf 文件中输入以下行(当然是在删除以前的更改之后)。在以下配置中,您的默认httpFolder表示默认的http文件夹。您可能已经更改了它。因此,请根据您的系统进行更正。
<VirtualHost *:80>
DocumentRoot "/Applications/mampstack-5.4.20-0/apache2/htdocs/yourDefaultHttpFolder"
ServerName 127.0.0.1
ServerAlias localhost
SetEnv APPLICATION_ENV development
SetEnv APPLICATION_DOMAIN localhost
<Directory /Applications/mampstack-5.4.20-0/apache2/htdocs/yourDefaultHttpFolder>
RewriteEngine on
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^ http://%{HTTP_HOST}:8080%{REQUEST_URI} [P]
</Directory>
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/Applications/mampstack-5.4.20-0/apache2/htdocs/mext-pst-dashboard/web"
ServerName mext-pst.local
ServerAlias mext-pst.local
SetEnv APPLICATION_ENV development
SetEnv APPLICATION_DOMAIN mext-pst.local
</VirtualHost>
此配置在我的服务器上有效,当我尝试使用 80 访问时,它会将 URL 重写到我的 8080 端口,我看到该文件夹的内容,而不是默认索引页。
您必须将端口更改为 *:80,如果您要使用不同的名称,那么服务器名称请确保在您的 httpd.conf 中使用 NameVirtualHost *:80。
由于您没有侦听端口 80
,当您转到没有端口的 URL 时出现错误似乎是正确的结果,对吧?
当你去港口8080
时,你会得到一个Proxy Error
.您确定端口 8080
上没有运行其他软件,或者您的浏览器没有输入代理吗? Apache
不会给Proxy Error
.我怀疑此错误来自其他地方。
关于您的配置,我不确定您要实现的目标是什么,但是,如果您想在去localhost:8080
时提供一些文件,并在您去mext-pst.local:8080
时提供另一组文件,而不是您几乎在那里,NameVirtualHost *:8080
是正确的,需要在那里, 删除重定向行,因为您不需要它们(除非我的假设是错误的)。