linux环境apache多端口配置虚拟主机的方法深入介绍
2023-06-13 09:15:01 时间
默认情况下,linux上apache使用的
默认文档目录是:/var/www
默认端口是:80
如果想发布自己的一个系统资源目录,可以使用下面的方法,执行如下命令:
(1)添加监听端口
#cd/etc/apache2
#vimports.conf
文件添加:
NameVirtualHost*:8000
Listen8000
(2)配置虚拟目录
#cd/etc/apache2/sites-available
#cpdefaultdefault-me
#vimdefault-me
文件内容如下:
复制代码代码如下:
默认文档目录是:/var/www
默认端口是:80
如果想发布自己的一个系统资源目录,可以使用下面的方法,执行如下命令:
#vimports.conf
文件添加:
NameVirtualHost*:8000
Listen8000
#cd/etc/apache2/sites-available
#cpdefaultdefault-me
#vimdefault-me
文件内容如下:
<VirtualHost*:8000>
ServerAdminwebmaster@localhost
DocumentRoot/wwwroot
<Directory/>
OptionsFollowSymLinks
AllowOverrideNone
</Directory>
<Directory/wwwroot/>
OptionsIndexesFollowSymLinksMultiViews
AllowOverrideNone
Orderallow,deny
allowfromall
</Directory>
ErrorLog/var/log/apache2/error.log
#Possiblevaluesinclude:debug,info,notice,warn,error,crit,
#alert,emerg.
LogLevelwarn
CustomLog/var/log/apache2/access.logcombined
</VirtualHost>
粗体部分是关键点。
如果能够正常访问就说明配置正确了。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#VirtualHosts
#
#Ifyouwanttomaintainmultipledomains/hostnamesonyour
#machineyoucansetupVirtualHostcontainersforthem.Mostconfigurations
#useonlyname-basedvirtualhostssotheserverdoesn"tneedtoworryabout
#IPaddresses.Thisisindicatedbytheasterisksinthedirectivesbelow.
#
#Pleaseseethedocumentationat
#<URL:http://httpd.apache.org/docs/2.2/vhosts/>
#forfurtherdetailsbeforeyoutrytosetupvirtualhosts.
#
#Youmayusethecommandlineoption"-S"toverifyyourvirtualhost
#configuration.
#
#Usename-basedvirtualhosting.
#
NameVirtualHost*:81
NameVirtualHost*:82
NameVirtualHost*:83
NameVirtualHost*:84
NameVirtualHost*:85
NameVirtualHost*:86
#
#VirtualHostexample:
#AlmostanyApachedirectivemaygointoaVirtualHostcontainer.
#ThefirstVirtualHostsectionisusedforallrequeststhatdonot
#matchaServerNameorServerAliasinany<VirtualHost>block.
#
<VirtualHost*:81>
ServerAdminjsw7001@hotmail.com
DocumentRootD:/AppServ/www/www-nongye
ServerNamewww.dede.com
ErrorLogD:/AppServ/www/www-nongye/errornongye.log
CustomLoglogs/dummy-host2.appservnetwork.com-access_logcommon
</VirtualHost>
<VirtualHost*:82>
<Directory"D:/AppServ/www-chinaec">
OptionsFollowSymLinks
#Denyfromall
Allowfromall
</Directory>
ServerAdminjsw7001@hotmail.com
DocumentRootD:/AppServ/www-chinaec
ServerNamewww.dede.com
DirectoryIndexindex.phpindex.html
ErrorLogD:/AppServ/www-chinaec/errornongjiale.log
CustomLoglogs/dummy-host2.appservnetwork.com-access_logcommon
</VirtualHost>
<VirtualHost*:83>
ServerAdminjsw7001@hotmail.com
DocumentRootD:/AppServ/www/www-05110
ServerNamewww.dede.com
ErrorLogD:/AppServ/www/www-05110/errornong05110.log
CustomLoglogs/dummy-host2.appservnetwork.com-access_logcommon
</VirtualHost>
<VirtualHost*:84>
ServerAdminjsw7001@hotmail.com
DocumentRootD:/AppServ/www/wordpress
ServerNamewww.dede.com
ErrorLogD:/AppServ/www/wordpress/errornongwordpress.log
CustomLoglogs/dummy-host2.appservnetwork.com-access_logcommon
</VirtualHost>
<VirtualHost*:85>
ServerAdminjsw7001@hotmail.com
DocumentRootD:/AppServ/www/magento
ServerNamewww.dede.com
ErrorLogD:/AppServ/www/magento/errormagento.log
CustomLoglogs/dummy-host2.appservnetwork.com-access_logcommon
</VirtualHost>
<VirtualHost*:86>
ServerAdminjsw7001@hotmail.com
DocumentRootD:/AppServ/www/magento1322
ServerNamewww.dede.com
ErrorLogD:/AppServ/www/magento1322/errormagento1322.log
CustomLoglogs/dummy-host2.appservnetwork.com-access_logcommon
</VirtualHost>
<VirtualHost*:88>
ServerAdminjsw7001@hotmail.com
DocumentRootD:/AppServ/www/www-nongjiale
ServerNamewww.dede.com
ErrorLogD:/AppServ/www/www-nongjiale/errornongjiale.log
CustomLoglogs/dummy-host2.appservnetwork.com-access_logcommon
</VirtualHost>
<VirtualHost*:80>
ServerAdminwebmaster@dummy-host2.x
DocumentRoot"C:/Apache2.2/docs/dummy-host2.x"
ServerNamedummy-host2.x
ErrorLog"logs/dummy-host2.x-error.log"
CustomLog"logs/dummy-host2.x-access.log"common
</VirtualHost>
1、单域名单端口设置
如:www.abc.com默认用80访问
特别说明,apache的配置默认都在安装目录下的conf目录里面
或者是/etc/apache2
不过一定要注意,listen.conf文件中端口监听是否开启
如下图,表示已经开启80端口监听
直接默认
1、单域名单端口设置
如:www.abc.com默认用80访问
特别说明,apache的配置默认都在安装目录下的conf目录里面
或者是/etc/apache2
不过一定要注意,listen.conf文件中端口监听是否开启
如下图,表示已经开启80端口监听
直接默认修改default-server.conf
这个配置最好简单
安装好了,之后,默认已经能够使用了,只是要把它修改成你需要的域名及访问路径罢了。
给一个标准配置吧
DocumentRoot"/srv/www/htdocs"
#
#ConfiguretheDocumentRoot
#
<Directory"/srv/www/htdocs">
#PossiblevaluesfortheOptionsdirectiveare"None","All",
#oranycombinationof:
# IndexesIncludesFollowSymLinksSymLinksifOwnerMatchExecCGIMultiViews
#
#Notethat"MultiViews"mustbenamed*explicitly*---"OptionsAll"
#doesn"tgiveittoyou.
#
#TheOptionsdirectiveisbothcomplicatedandimportant. Pleasesee
#http://httpd.apache.org/docs-2.2/mod/core.html#options
#formoreinformation.
OptionsNone
#AllowOverridecontrolswhatdirectivesmaybeplacedin.htaccessfiles.
#Itcanbe"All","None",oranycombinationofthekeywords:
# OptionsFileInfoAuthConfigLimit
AllowOverrideNone
#Controlswhocangetstufffromthisserver.
Orderallow,deny
Allowfromall
</Directory>
2、单域名多端口设置
<Directory"/srv/www/htdocs/bbs">
OptionsNone
AllowOverrideNone
Orderallow,deny
Allowfromall
</Directory>
<Directory"/srv/www/htdocs/">
OptionsNone
AllowOverrideNone
Orderallow,deny
Allowfromall
</Directory>
NameVirtualHost *:80
NameVirtualHost *:81
<VirtualHost*:80>
DirectoryIndex index.htmlindex.php
ServerName "www.abc.com"
DocumentRoot "/srv/www/htdocs/"
</VirtualHost>
<VirtualHost*:81>
DirectoryIndex index.php
ServerName "www.abc.com:81"
DocumentRoot "/srv/www/htdocs/bbs/"
</VirtualHost>
3、多域名多端口设置
<Directory"/srv/www/htdocs/btc">
OptionsNone
AllowOverrideNone
Orderallow,deny
Allowfromall
</Directory>
<Directory"/srv/www/htdocs/bbs">
OptionsNone
AllowOverrideNone
Orderallow,deny
Allowfromall
</Directory>
<Directory"/srv/www/htdocs/">
OptionsNone
AllowOverrideNone
Orderallow,deny
Allowfromall
</Directory>
NameVirtualHost *:80
NameVirtualHost *:81
<VirtualHost*:80>
DirectoryIndex index.htmlindex.php
ServerName "www.abc.com"
DocumentRoot "/srv/www/htdocs/"
</VirtualHost>
<VirtualHost*:80>
DirectoryIndex index.htmlindex.php
ServerName "www.btc.com"
DocumentRoot "/srv/www/htdocs/btc"
</VirtualHost>
<VirtualHost*:81>
DirectoryIndex index.php
ServerName "www.abc.com:81"
DocumentRoot "/srv/www/htdocs/bbs/"
</VirtualHost>
需要注意的问题是,多端口监听,一定要注意listen.conf文件,是否开启了相应端口。
相关文章
- Linux下获取路径的简单方法(linux获取路径)
- Linux启动:解压操作的步骤(linux启动解压)
- 让智能手机也可以完成Kali Linux渗透测试(手机kalilinux)
- 包Linux快速安装PKG包的方法(linux怎么安装pkg)
- Linux查看内存页大小的方法(linux查看内存页大小)
- 解锁Linux网关:掌握基本命令(linux网关命令)
- Linux 驱动注册:开启新世界之门(驱动注册linux)
- 调整调整Linux系统时钟时间的方法(linux时钟时间)
- 内容Linux读取USB存储设备内容的方法(linux读取usb)
- 解决Linux系统僵死进程的方法(linux僵死进程)
- Linux系统改变文件名的方法(linux文件改名字)
- 解决虚拟机Linux网络问题(虚拟机linux连不上网)
- Linux的分支:探索开源世界的新纪元(linux的分支)
- Linux自动发送邮件的实现方法(linux自动发邮件)
- 关闭Linux防火墙:简便方法(关闭linux的防火墙)
- Linux系统的发展历程及分支(linux的分支)
- 互助学习:Linux贴吧(linux贴吧)
- 管控Linux系统:关闭防火墙(关闭linux的防火墙)
- Linux系统登录方法简介及步骤(linux怎么登录)
- Linux命令教程:文件重命名技巧详解(linux如何文件重命名)
- 深入探讨 Linux 网关代理的实现原理与应用技巧(linux网关代理)
- Linux程序:自由下载、自由分享(linux程序下载)
- 学习Linux必备:掌握更高效的文件查看方法——使用Linux命令more(linux命令more)
- Linux系统中的目录结构及其功能介绍(linux系统目录结构)
- Linux在PDF格式上的应用前景(linux pdf)
- Linux进程间交流:以信号传递信息(linux进程间通信信号)
- Linux安装WHl:一步一步指引(linux安装whl)
- 探索 Linux 下查看连接数的方法(查看连接数linux)