简体   繁体   English

列出了Apache本地虚拟主机,但不起作用

[英]Apache local virtual host is listed but doesn't work

I need help configuring my website to be accessed in the local server as a virtual directory in Apache. 我需要将我的网站配置为在Apache中作为虚拟目录在本地服务器中进行访问的帮助。 I am trying to use the port 8050, and when i open localhost:8050 , it shows: 我正在尝试使用端口8050,当我打开localhost:8050时,它显示:

This site can't be reached localhost refused to connect. 无法访问此站点本地主机拒绝连接。 ERR_CONNECTION_REFUSED ERR_CONNECTION_REFUSED

when i try to access my localhost:80 in the browser, it shows the default blank page with the message "It Works" 当我尝试在浏览器中访问我的localhost:80时,它显示默认空白页面,并显示消息“ It Works”
if i change my virtualhost to *.80 in the config, it keeps showing the default message "It Works", instead of my page. 如果我在配置中将virtualhost更改为* .80,它会一直显示默认消息“ It Works”,而不是我的页面。

apachectl -t returns Syntax OK apachectl -t返回语法OK
the command: 命令:
apachectl -t -D DUMP_VHOSTS returns: apachectl -t -D DUMP_VHOSTS返回:

VirtualHost configuration: VirtualHost配置:
*:8050 personal.com (/private/etc/apache2/extra/httpd-vhosts.conf:24) *:8050 personal.com(/private/etc/apache2/extra/httpd-vhosts.conf:24)

the Servername in my httpd.conf file is localhost, and it also contains: 我的httpd.conf文件中的Servername是localhost,它还包含:
Listen 8050 听8050
and
Listen localhost:8050 听本地主机:8050

this is my httpd-vhosts in etc/apache2/extra/httpd-vhosts.conf: 这是我在etc / apache2 / extra / httpd-vhosts.conf中的httpd-vhosts:

<VirtualHost *:8050>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/Users/renatobento/Documents/Projetos/Personal"
    ServerName personal.com
    ErrorLog "/private/var/log/apache2/personal.com-error_log"
    CustomLog "/private/var/log/apache2/personal.com-access_log" common
<Directory "/Users/renatobento/Documents/Projetos/Personal">
    Order allow,deny
    Allow from all
    Require all granted
</Directory>
</VirtualHost>

The path "/Users/renatobento/Documents/Projetos/Personal" seems correct, and contains a simple index.html with some content, which works in the browser with file protocol: "file:///Users/renatobento/Documents/Projetos/personal/index.html" 路径“ / Users / renatobento / Documents / Projetos / Personal”似乎是正确的,并且包含带有某些内容的简单index.html,可在浏览器中使用文件协议运行:“ file:/// Users / renatobento / Documents / Projetos /personal/index.html”

Already executed apachectl stop , apachectl start , and apachectl restart thousand times 已执行apachectl stopapachectl startapachectl restart数千次

after the stop command, the localhost:80 still shows the message "It Works" 在stop命令之后,localhost:80仍然显示消息“ It Works”

I am using MAC OSX 10.3 high sierra, apache 2.4 我正在使用MAC OSX 10.3 High Sierra,Apache 2.4

Server version: Apache/2.4.33 (Unix) Server built: Apr 3 2018 23:45:11 Server's Module Magic Number: 20120211:76 Server loaded: APR 1.5.2, APR-UTIL 1.5.4 Compiled using: APR 1.5.2, APR-UTIL 1.5.4 Architecture: 64-bit Server MPM: prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_FLOCK_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=256 -D HTTPD_ROOT="/usr" -D SUEXEC_BIN="/usr/bin/suexec" -D DEFAULT_PIDLOG="/private/var/run/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types" -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf" 服务器版本:Apache / 2.4.33(Unix)服务器内部版本:2018年4月3日23:45:11服务器模块编号:20120211:76服务器已加载:APR 1.5.2,APR-UTIL 1.5.4使用以下命令编译:APR 1.5。 2,APR-UTIL 1.5.4体系结构:64位服务器MPM:前叉线程:否分支:是(可变进程计数)服务器使用...编译-D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6(启用了IPv4映射的地址)-D APR_USE_FLOCK_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT / EXE = / DATE / ID = BIN -D /run/httpd.pid“ -D DEFAULT_SCOREBOARD =” logs / apache_runtime_status“ -D DEFAULT_ERRORLOG =” logs / error_log“ -D AP_TYPES_CONFIG_FILE =” / private / etc / apache2 / mime.types“ -D SERVER_CONFIG_FILE =” / private / etc /apache2/httpd.conf”

edit: tried with a different port :9050 but still not working 编辑:尝试使用其他端口:9050,但仍无法正常工作

Check whether permissions for DocumentRoot 检查是否有DocumentRoot 权限

/Users/renatobento/Documents/Projetos/Personal

are set to be accessible for everyone . 设置为所有人都可以使用

Your overall config seems to be good. 您的整体配置似乎很好。


Check your /etc/hosts file, if it contains something like 检查您的/etc/hosts文件,如果其中包含类似

127.0.0.1    localhost
127.0.0.1    personal.com

To edit this file, type sudo nano /etc/hosts in Terminal and after editing, type sudo killall -HUP mDNSResponder to flush DNS cache. 要编辑此文件,请在终端中键入sudo nano /etc/hosts ,然后在编辑后键入sudo killall -HUP mDNSResponder刷新DNS缓存。

Problem solved. 问题解决了。 Weird, looks like restarting Apache and cache commands sometimes are not enough. 很奇怪,看起来重启Apache和缓存命令有时还不够。 The message changed to 403-forbidden after a system restart. 系统重新启动后,该消息更改为403-禁止。

I checked the ports with lsof -nP -i4TCP:80 | grep LISTEN 我用lsof -nP -i4TCP:80 | grep LISTEN检查了端口lsof -nP -i4TCP:80 | grep LISTEN lsof -nP -i4TCP:80 | grep LISTEN lsof -nP -i4TCP:8050 | grep LISTEN lsof -nP -i4TCP:80 | grep LISTEN lsof -nP -i4TCP:8050 | grep LISTEN lsof -nP -i4TCP:8050 | grep LISTEN lsof -nP -i4TCP:9050 | grep LISTEN lsof -nP -i4TCP:8050 | grep LISTEN lsof -nP -i4TCP:9050 | grep LISTEN lsof -nP -i4TCP:9050 | grep LISTEN

and it showed 4 httpd process listening to :80 even with apache stopped, then after a reboot appeared a process listening in the correct port. 它显示了4个httpd进程,即使apache停止也正在监听:80,然后在重新启动后出现了一个监听正确端口的进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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