在linux上用apachebuild立一个子域

我不能相信我以前没有这样做过,但我想要一个明确的答案,所以我都前进了。

我在/etc/apache2/sites-available/mysite上有一个apacheconfiguration文件,如下所示:

 <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /home/sam/public_html <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /home/sam/public_html> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 

所以这服务的HTML和PHP文件从~/public_html一切正常。 但我有多个项目,所以想开始使用子域名。 我想要做的是将~/public_html/myproject/中的文件作为myproject.localhost的根目录。

我已经尝试添加以下到我的Apache文件的底部:

 <VirtualHost myproject.localhost> DocumentRoot ~/public_html/myproject/ ServerName myproject.localhost ServerAdmin admin@myproject.localhost <Directory ~/public_html/myproject> Options Indexes FollowSymLinks AllowOverride FileInfo Order allow,deny Allow from all </Directory> </VirtualHost> 

但Apache的抱怨:

 Restarting web server: apache2[Tue Aug 20 11:06:19 2013] [error] (EAI 2)Name or service not known: Could not resolve host name myproject.localhost -- ignoring! ... waiting [Tue Aug 20 11:06:20 2013] [error] (EAI 2)Name or service not known: Could not resolve host name myproject.localhost -- ignoring! 

我知道我犯了一个基本错误,但我不确定它是什么。

任何帮助非常感谢。

编辑

这是我现在的完整文件:

 <VirtualHost *:80> DocumentRoot /home/sam/public_html/ryua1226-magento/ ServerName mydomain.localhost ServerAdmin admin@mydomain.localhost <Directory /home/sam/public_html/ryua1226-magento> Options Indexes FollowSymLinks AllowOverride FileInfo Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /home/sam/public_html <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /home/sam/public_html> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 

Solutions Collecting From Web of "在linux上用apachebuild立一个子域"

你告诉Apache你要在<VirtualHost>标签里面回答它的IP和端口,所以这里的*表示任何IP,但是在端口80上接受这个站点的请求。接下来,你需要告诉Apache文档根目录在哪里。 ~/表示你的默认主目录,所以如果你的DocumentRoot恰好是默认的home变量,那么它将与你现有的表示法(取决于你正在运行服务器的用户)一起工作。 然后你会声明服务器名称。

除非您使用别名,否则您创建主机的每个域名都需要自己的虚拟主机指令。

 <VirtualHost *:80> DocumentRoot /home/sam/public_html serverName myproject.localhost # Other directives here </VirtualHost> <VirtualHost *:80> DocumentRoot /home/sam/public_html/myproject serverName myotherproject.localhost # Other directives here </VirtualHost> 

关于主机除此之外,您为主机创建的任何特殊名称还需要进入主机文件或DNS服务器。 这样任何寻找你的服务器的网络浏览器都可以找到它,而不必输入IP。 既然你可能有多个主机与你的设置在同一个IP上,如果你只是尝试访问只有IP的服务器,你只会得到第一个主机对IP的响应(通常是虚拟主机列表中的顶部) 。

添加到AbsoluteƵERØ的答案(如果我们正在尝试这个本地机器 ),我们需要更新hosts文件,可以在这里找到:

Ubuntu:/ etc / hosts

Windows:c:\ windows \ system32 \ drivers \ etc \ hosts

Mac:/ etc / hosts

注意:这是要求告诉您的本地机器给定的子域指向您的本地机器本身

我正在使用Windows操作系统,但我也检查了在Ubuntu的这一点。 它的工作非常好。

这里是我的httpd.conf文件

 # # This is the main Apache HTTP server configuration file. It contains the # configuration directives that give the server its instructions. # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information. # In particular, see # <URL:http://httpd.apache.org/docs/2.4/mod/directives.html> # for a discussion of each configuration directive. # # Do NOT simply read the instructions in here without understanding # what they do. They're here only as hints or reminders. If you are unsure # consult the online docs. You have been warned. # # Configuration and logfile names: If the filenames you specify for many # of the server's control files begin with "/" (or "drive:/" for Win32), the # server will use that explicit path. If the filenames do *not* begin # with "/", the value of serverRoot is prepended -- so "logs/access_log" # with serverRoot set to "/usr/local/apache2" will be interpreted by the # server as "/usr/local/apache2/logs/access_log", whereas "/logs/access_log" # will be interpreted as '/logs/access_log'. # # NOTE: Where filenames are specified, you must use forward slashes # instead of backslashes (eg, "c:/apache" instead of "c:\apache"). # If a drive letter is omitted, the drive on which httpd.exe is located # will be used by default. It is recommended that you always supply # an explicit drive letter in absolute paths to avoid confusion. # # serverRoot: The top of the directory tree under which the server's # configuration, error, and log files are kept. # # Do not add a slash at the end of the directory path. If you point # serverRoot at a non-local disk, be sure to specify a local disk on the # Mutex directive, if file-based mutexes are used. If you wish to share the # same serverRoot for multiple httpd daemons, you will need to change at # least PidFile. # serverRoot "c:/wamp/bin/apache/apache2.4.4" # # Mutex: Allows you to set the mutex mechanism and mutex file directory # for individual mutexes, or change the global defaults # # Uncomment and change the directory if mutexes are file-based and the default # mutex file directory is not on a local disk or is not appropriate for some # other reason. # # Mutex default:logs # # listn: Allows you to bind Apache to specific IP addresses and/or # ports, instead of the default. See also the <VirtualHost> # directive. # # Change this to listn on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses. # #listn 12.34.56.78:80 listn 80 # # Dynamic Shared Object (DSO) Support # # To be able to use the functionality of a module which was built as a DSO you # have to place corresponding `Loadmodulee' lines at this location so the # directives contained in it are actually available _before_ they are used. # Statically compiled modules (those listed by `httpd -l') do not need # to be loaded here. # # Example: # Loadmodulee foo_module modules/mod_foo.so # Loadmodulee access_compat_module modules/mod_access_compat.so Loadmodulee actions_module modules/mod_actions.so Loadmodulee alias_module modules/mod_alias.so Loadmodulee allowmethods_module modules/mod_allowmethods.so Loadmodulee asis_module modules/mod_asis.so Loadmodulee auth_basic_module modules/mod_auth_basic.so #Loadmodulee auth_digest_module modules/mod_auth_digest.so #Loadmodulee authn_anon_module modules/mod_authn_anon.so Loadmodulee authn_core_module modules/mod_authn_core.so #Loadmodulee authn_dbd_module modules/mod_authn_dbd.so #Loadmodulee authn_dbm_module modules/mod_authn_dbm.so Loadmodulee authn_file_module modules/mod_authn_file.so #Loadmodulee authn_socache_module modules/mod_authn_socache.so #Loadmodulee authnz_ldap_module modules/mod_authnz_ldap.so Loadmodulee authz_core_module modules/mod_authz_core.so #Loadmodulee authz_dbd_module modules/mod_authz_dbd.so #Loadmodulee authz_dbm_module modules/mod_authz_dbm.so Loadmodulee authz_groupfile_module modules/mod_authz_groupfile.so Loadmodulee authz_host_module modules/mod_authz_host.so #Loadmodulee authz_owner_module modules/mod_authz_owner.so Loadmodulee authz_user_module modules/mod_authz_user.so Loadmodulee autoindex_module modules/mod_autoindex.so #Loadmodulee buffer_module modules/mod_buffer.so #Loadmodulee cache_module modules/mod_cache.so #Loadmodulee cache_disk_module modules/mod_cache_disk.so #Loadmodulee cern_meta_module modules/mod_cern_meta.so Loadmodulee cgi_module modules/mod_cgi.so #Loadmodulee charset_lite_module modules/mod_charset_lite.so #Loadmodulee data_module modules/mod_data.so #Loadmodulee dav_module modules/mod_dav.so #Loadmodulee dav_fs_module modules/mod_dav_fs.so #Loadmodulee dav_lock_module modules/mod_dav_lock.so #Loadmodulee dbd_module modules/mod_dbd.so #Loadmodulee deflate_module modules/mod_deflate.so Loadmodulee dir_module modules/mod_dir.so #Loadmodulee dumpio_module modules/mod_dumpio.so Loadmodulee env_module modules/mod_env.so #Loadmodulee expires_module modules/mod_expires.so #Loadmodulee ext_filter_module modules/mod_ext_filter.so #Loadmodulee file_cache_module modules/mod_file_cache.so #Loadmodulee filter_module modules/mod_filter.so #Loadmodulee headers_module modules/mod_headers.so #Loadmodulee heartbeat_module modules/mod_heartbeat.so #Loadmodulee heartmonitor_module modules/mod_heartmonitor.so #Loadmodulee ident_module modules/mod_ident.so #Loadmodulee imagemap_module modules/mod_imagemap.so Loadmodulee include_module modules/mod_include.so #Loadmodulee info_module modules/mod_info.so Loadmodulee isapi_module modules/mod_isapi.so #Loadmodulee lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so #Loadmodulee lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so #Loadmodulee lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so #Loadmodulee lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so #Loadmodulee ldap_module modules/mod_ldap.so #Loadmodulee logio_module modules/mod_logio.so Loadmodulee log_config_module modules/mod_log_config.so #Loadmodulee log_debug_module modules/mod_log_debug.so #Loadmodulee log_forensic_module modules/mod_log_forensic.so #Loadmodulee lua_module modules/mod_lua.so Loadmodulee mime_module modules/mod_mime.so #Loadmodulee mime_magic_module modules/mod_mime_magic.so Loadmodulee negotiation_module modules/mod_negotiation.so #Loadmodulee proxy_module modules/mod_proxy.so #Loadmodulee proxy_ajp_module modules/mod_proxy_ajp.so #Loadmodulee proxy_balancer_module modules/mod_proxy_balancer.so #Loadmodulee proxy_connect_module modules/mod_proxy_connect.so #Loadmodulee proxy_express_module modules/mod_proxy_express.so #Loadmodulee proxy_fcgi_module modules/mod_proxy_fcgi.so #Loadmodulee proxy_ftp_module modules/mod_proxy_ftp.so #Loadmodulee proxy_html_module modules/mod_proxy_html.so #Loadmodulee proxy_http_module modules/mod_proxy_http.so #Loadmodulee proxy_scgi_module modules/mod_proxy_scgi.so #Loadmodulee ratelimit_module modules/mod_ratelimit.so #Loadmodulee reflector_module modules/mod_reflector.so #Loadmodulee remoteip_module modules/mod_remoteip.so #Loadmodulee request_module modules/mod_request.so #Loadmodulee reqtimeout_module modules/mod_reqtimeout.so #Loadmodulee rewrite_module modules/mod_rewrite.so #Loadmodulee sed_module modules/mod_sed.so #Loadmodulee session_module modules/mod_session.so #Loadmodulee session_cookie_module modules/mod_session_cookie.so #Loadmodulee session_crypto_module modules/mod_session_crypto.so #Loadmodulee session_dbd_module modules/mod_session_dbd.so Loadmodulee setenvif_module modules/mod_setenvif.so #Loadmodulee slotmem_plain_module modules/mod_slotmem_plain.so #Loadmodulee slotmem_shm_module modules/mod_slotmem_shm.so #Loadmodulee socache_dbm_module modules/mod_socache_dbm.so #Loadmodulee socache_memcache_module modules/mod_socache_memcache.so #Loadmodulee socache_shmcb_module modules/mod_socache_shmcb.so #Loadmodulee speling_module modules/mod_speling.so #Loadmodulee ssl_module modules/mod_ssl.so #Loadmodulee status_module modules/mod_status.so #Loadmodulee substitute_module modules/mod_substitute.so #Loadmodulee unique_id_module modules/mod_unique_id.so #Loadmodulee userdir_module modules/mod_userdir.so #Loadmodulee usertrack_module modules/mod_usertrack.so #Loadmodulee version_module modules/mod_version.so #Loadmodulee vhost_alias_module modules/mod_vhost_alias.so #Loadmodulee watchdog_module modules/mod_watchdog.so #Loadmodulee xml2enc_module modules/mod_xml2enc.so Loadmodulee php5_module "c:/wamp/bin/php/php5.4.16/php5apache2_4.dll" <Ifmodulee unixd_module> # # If you wish httpd to run as a different user or group, you must run # httpd as root initially and it will switch. # # User/Group: The name (or #number) of the user/group to run httpd as. # It is usually good practice to create a dedicated user and group for # running httpd, as with most system services. # User daemon Group daemon </Ifmodulee> # 'Main' server configuration # # The directives in this section set up the values used by the 'main' # server, which responds to any requests that aren't handled by a # <VirtualHost> definition. These values also provide defaults for # any <VirtualHost> containers you may define later in the file. # # All of these directives may appear inside <VirtualHost> containers, # in which case these default settings will be overridden for the # virtual host being defined. # # # serverAdmin: Your address, where problems with the server should be # e-mailed. This address appears on some server-generated pages, such # as error documents. eg admin@your-domain.com # serverAdmin admin@example.com # # serverName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # serverName localhost # # Deny access to the entirety of your server's filesystem. You must # explicitly permit access to web content directories in other # <Directory> blocks below. # <Directory /> AllowOverride none Require all granted </Directory> # # Note that from this point forward you must specifically allow # particular features to be enabled - so if something's not working as # you might expect, make sure that you have specifically enabled it # below. # # # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "c:/wamp/www/mwww/" <Directory "c:/wamp/www/mwww"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride All # # Controls who can get stuff from this server. # # Require all granted # onlineoffline tag - don't remove Order Deny,Allow Deny from all Allow from 127.0.0.1 Allow from ::1 Allow from localhost </Directory> # # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # <Ifmodulee dir_module> DirectoryIndex index.php index.php3 index.html index.htm </Ifmodulee> # # The following lines prevent .htaccess and .htpasswd files from being # viewed by Web clients. # <Files ".ht*"> Require all denied </Files> # # ErrorLog: The location of the error log file. # If you do not specify an ErrorLog directive within a <VirtualHost> # container, error messages relating to that virtual host will be # logged here. If you *do* define an error logfile for a <VirtualHost> # container, that host's errors will be logged there and not here. # #ErrorLog "logs/error.log" ErrorLog "c:/wamp/logs/apache_error.log" # # LogLevel: Control the number of messages logged to the error_log. # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. # LogLevel warn <Ifmodulee log_config_module> # # The following directives define some format nicknames for use with # a CustomLog directive (see below). # LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common <Ifmodulee logio_module> # You need to enable mod_logio.c to use %I and %O LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio </Ifmodulee> # # The location and format of the access logfile (Common Logfile Format). # If you do not define any access logfiles within a <VirtualHost> # container, they will be logged here. Contrariwise, if you *do* # define per-<VirtualHost> access logfiles, transactions will be # logged therein and *not* in this file. # CustomLog "logs/access.log" common CustomLog "c:/wamp/logs/access.log" common # # If you prefer a logfile with access, agent, and referer information # (Combined Logfile Format) you can use the following directive. # #CustomLog "logs/access.log" combined </Ifmodulee> <Ifmodulee alias_module> # # Redirect: Allows you to tell clients about documents that used to # exist in your server's namespace, but do not anymore. The client # will make a new request for the document at its new location. # Example: # Redirect permanent /foo http://www.example.com/bar # # Alias: Maps web paths into filesystem paths and is used to # access content that does not live under the DocumentRoot. # Example: # Alias /webpath /full/filesystem/path # # If you include a trailing / on /webpath then the server will # require it to be present in the URL. You will also likely # need to provide a <Directory> section to allow access to # the filesystem path. # # ScriptAlias: This controls which directories contain server scripts. # ScriptAliases are essentially the same as Aliases, except that # documents in the target directory are treated as applications and # run by the server when requested rather than as documents sent to the # client. The same rules about trailing "/" apply to ScriptAlias # directives as to Alias. # ScriptAlias /cgi-bin/ "c:/wamp/cgi-bin/" </Ifmodulee> <Ifmodulee cgid_module> # # ScriptSock: On threaded servers, designate the path to the UNIX # socket used to communicate with the CGI daemon of mod_cgid. # #Scriptsock cgisock </Ifmodulee> # # "c:/wamp/cgi-bin" should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # <Directory "c:/wamp/cgi-bin"> AllowOverride None Options None Require all granted </Directory> <Ifmodulee mime_module> # # TypesConfig points to the file containing the list of mappings from # filename extension to MIME-type. # TypesConfig conf/mime.types # # AddType allows you to add to or override the MIME configuration # file specified in TypesConfig for specific file types. # #AddType application/x-gzip .tgz # # AddEncoding allows you to have certain browsers uncompress # information on the fly. Note: Not all browsers support this. # #AddEncoding x-compress .Z #AddEncoding x-gzip .gz .tgz # # If the AddEncoding directives above are commented-out, then you # probably should define those extensions to indicate media types: # AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType application/x-httpd-php .php AddType application/x-httpd-php .php3 # # AddHandler allows you to map certain file extensions to "handlers": # actions unrelated to filetype. These can be either built into the server # or added with the Action directive (see below) # # To use CGI scripts outside of ScriptAliased directories: # (You will also need to add "ExecCGI" to the "Options" directive.) # #AddHandler cgi-script .cgi # For type maps (negotiated resources): #AddHandler type-map var # # Filters allow you to process content before it is sent to the client. # # To parse .shtml files for server-side includes (SSI): # (You will also need to add "Includes" to the "Options" directive.) # #AddType text/html .shtml #AddOutputFilter INCLUDES .shtml </Ifmodulee> # # The mod_mime_magic module allows the server to use various hints from the # contents of the file itself to determine its type. The MIMEMagicFile # directive tells the module where the hint definitions are located. # #MIMEMagicFile conf/magic # # Customizable error responses come in three flavors: # 1) plain text 2) local redirects 3) external redirects # # Some examples: #ErrorDocument 500 "The server made a boo boo." #ErrorDocument 404 /missing.html #ErrorDocument 404 "/cgi-bin/missing_handler.pl" #ErrorDocument 402 http://www.example.com/subscription_info.html # # # MaxRanges: Maximum number of Ranges in a request before # returning the entire resource, or one of the special # values 'default', 'none' or 'unlimited'. # Default setting is to accept 200 Ranges. #MaxRanges unlimited # # EnableMMAP and EnableSendfile: On systems that support it, # memory-mapping or the sendfile syscall may be used to deliver # files. This usually improves server performance, but must # be turned off when serving from networked-mounted # filesystems or if support for these functions is otherwise # broken on your system. # Defaults: EnableMMAP On, EnableSendfile Off # #EnableMMAP off #EnableSendfile on # Supplemental configuration # # The configuration files in the conf/extra/ directory can be # included to add extra features or to modify the default configuration of # the server, or you may simply copy their contents here and change as # necessary. # server-pool management (MPM specific) Include conf/extra/httpd-mpm.conf # Multi-language error messages #Include conf/extra/httpd-multilang-errordoc.conf # Fancy directory listings #Include conf/extra/httpd-autoindex.conf # Language settings #Include conf/extra/httpd-languages.conf # User home directories #Include conf/extra/httpd-userdir.conf # Real-time info on requests and configuration #Include conf/extra/httpd-info.conf # Virtual hosts Include conf/extra/httpd-vhosts.conf # Local access to the Apache HTTP server Manual #Include conf/extra/httpd-manual.conf # Distributed authoring and versioning (WebDAV) #Include conf/extra/httpd-dav.conf # Various default settings #Include conf/extra/httpd-default.conf # Configure mod_proxy_html to understand HTML4/XHTML1 <Ifmodulee proxy_html_module> Include conf/extra/proxy-html.conf </Ifmodulee> # Secure (SSL/TLS) connections #Include conf/extra/httpd-ssl.conf # # Note: The following must must be present to support # starting without SSL on platforms with no /dev/random equivalent # but a statically compiled-in mod_ssl. # <Ifmodulee ssl_module> SSLRandomSeed startup builtin SSLRandomSeed connect builtin </Ifmodulee> # # uncomment out the below to deal with user agents that deliberately # violate open standards by misusing DNT (DNT *must* be a specific # end-user choice) # #<Ifmodulee setenvif_module> #BrowserMatch "MSIE 10.0;" bad_DNT #</Ifmodulee> #<Ifmodulee headers_module> #RequestHeader unset DNT env=bad_DNT #</Ifmodulee> IncludeOptional "c:/wamp/vhosts/*" Include "c:/wamp/alias/*" 

在这里我的httpd-vhosts.conf文件

 # Virtual Hosts # # Required modules: mod_log_config # If you want to maintain multiple domains/hostnames on your # machine you can setup VirtualHost containers for them. Most configurations # use only name-based virtual hosts so the server doesn't need to worry about # IP addresses. This is indicated by the asterisks in the directives below. # # Please see the documentation at # <URL:http://httpd.apache.org/docs/2.4/vhosts/> # for further details before you try to setup virtual hosts. # # You may use the command line option '-S' to verify your virtual host # configuration. # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a serverName or serverAlias in any <VirtualHost> block. # NameVirtualHost *.80 <VirtualHost *:80> serverName www.localhost DocumentRoot "C:/wamp/www/mwww/ <Directory "C:/wamp/www/mwww"> Options Indexes FollowSymLinks AllowOverride All </Directory> </VirtualHost> <VirtualHost *:80> serverName subhost DocumentRoot "C:/wamp/www/subwww/" <Directory "C:/wamp/www/subwww"> Options Indexes FollowSymLinks AllowOverride All </Directory> </VirtualHost> <VirtualHost *:80> serverName www.subhost DocumentRoot "C:/wamp/www/subwww/" <Directory "C:/wamp/www/subwww"> Options Indexes FollowSymLinks AllowOverride All </Directory> </VirtualHost> <VirtualHost *:80> serverName color.subhost DocumentRoot "C:/wamp/www/subwww/color/" <Directory "C:/wamp/www/subwww/color"> Options Indexes FollowSymLinks AllowOverride All </Directory> </VirtualHost> <VirtualHost *:80> serverName android.subhost DocumentRoot "C:/wamp/www/subwww/android/" <Directory "C:/wamp/www/subwww/android"> Options Indexes FollowSymLinks AllowOverride All </Directory> </VirtualHost> <VirtualHost *:80> serverName library.subhost DocumentRoot "C:/wamp/www/subwww/library/" <Directory "C:/wamp/www/subwww/library"> Options Indexes FollowSymLinks AllowOverride All </Directory> </VirtualHost> 

我的服务器的目录

 www- |-mwww |-subwww |-color |-android 

我的网址是

 for http://localhost/ -> www/mwww for http://subhost/ -> www/subwww for http://color.subhost/ -> www/subwww/color for http://android.subhost/ -> www/subwww/android 

尽管我正在使用Windows

我的C:/ Windows / system32 / drivers / etc / hosts文件的代码是

 # Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost 127.0.0.1 localhost 127.0.0.1 color.subhost 127.0.0.1 android.subhost 127.0.0.1 subhost 

我想,这将是有益的

VirtualHost指令应该包含IP地址或可解析的东西。 “myproject.localhost”不可解析,Apache告诉你。

你可能需要改变

 <VirtualHost *:80>