龙空技术网

Linux中Apache(httpd)配置反向代理二级域名

IT讲坛 130

前言:

今天各位老铁们对“apache二级域名重”可能比较关怀,大家都需要剖析一些“apache二级域名重”的相关知识。那么小编同时在网摘上网罗了一些有关“apache二级域名重””的相关资讯,希望我们能喜欢,各位老铁们快快来学习一下吧!

前言:

项目测试,部署,我们难免会想着将不同的项目放到不同的目录去访问,或则作为程序员的你,仅仅是为了把妹也好~本文带你简单配置httpd实现访问不同的一二级域名访问不同的项目目录结构。

阅读本文前需要你拥有自己的阿里云 ecs 服务器,并且一个域名。这里讲的httpd实现反向代理方案,至于https的代理需要ssl证书,这里不做讲解。当然了,还有nginx的实现,后面我再陆续给大家讲解。

正文:

1.先 yum list 看看有没有你可以的包

yum list httpd

2.如果有的话,比如我用 x86_64 版,就可以安装

yum install httpd.x86_64

3.添加二级域名解析

添加二级域名解析

4.修改代理配置

进入到安装目录:

cd /etc/httpd/confvi httpd.conf

完整 httpd.conf 配置如下

ServerRoot "/etc/httpd"Listen 80LoadModule alias_module modules/mod_alias.soLoadModule rewrite_module modules/mod_rewrite.soLoadModule php5_module modules/libphp5.soInclude conf.modules.d/*.confUser apacheGroup apacheServerAdmin root@localhost#ServerName ;Directory />AllowOverride noneRequire all denied</Directory>DocumentRoot "/var/www/html"<Directory "/var/www">AllowOverride NoneRequire all granted</Directory># Further relax access to the default document root:<Directory "/var/www/html">Options Indexes FollowSymLinksAllowOverride NoneRequire all granted</Directory><IfModule dir_module>DirectoryIndex index.html</IfModule><Files ".ht*">Require all denied</Files>ErrorLog "logs/error_log"LogLevel warn<IfModule log_config_module>LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"\"%{User-Agent}i\"" combinedLogFormat "%h %l %u %t \"%r\" %>s %b" common<IfModule logio_module>LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"\"%{User-Agent}i\" %I %O" combinedio</IfModule>CustomLog "logs/access_log" combined</IfModule><IfModule alias_module>ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"</IfModule><Directory "/var/www/cgi-bin">AllowOverride NoneOptions NoneRequire all granted</Directory><IfModule mime_module>TypesConfig /etc/mime.typesAddType application/x-compress .ZAddType application/x-gzip .gz .tgzAddType text/html .shtmlAddOutputFilter INCLUDES .shtml</IfModule>AddDefaultCharset UTF-8<IfModule mime_magic_module>MIMEMagicFile conf/magic</IfModule>EnableSendfile onIncludeOptional conf.d/*.conf<VirtualHost *:80>ServerAdmin scqshine@yeah.netDocumentRoot "/var/www/html"ServerName   beijingdesigner.comDirectoryIndex index.php index.html index.htm</VirtualHost><VirtualHost *:80>ServerAdmin scqshine@yeah.netDocumentRoot "/var/www/app"ServerName app.beijingdesigner.comServerAlias app.beijingdesigner.comDirectoryIndex index.php index.html index.htm</VirtualHost><VirtualHost *:80>ServerAdmin scqshine@yeah.netDocumentRoot "/var/www/contact"ServerName contact.beijingdesigner.comServerAlias contact.beijingdesigner.comDirectoryIndex index.php index.html index.htm</VirtualHost>

编辑完后:ew!保存退出即可。

说明:

这里模拟的是三个目录,你可以将你的项目分别部署到这三个目录进行访问。

为什么端口都写成 80,因为 http 访问 ip 后不跟端口号的话,

会自动跳转到 80 端口,所以这里配好 80 后,你部署好项目,直

接重启 httpd 服务,浏览器输入你的一级域名/二级域名不带端口

号,直接就打开了你的上面配置的< DirectoryIndex >的项目了,比

如 index.html/index.php/index.htm等。如果你还没准备好一个

完整的 javaweb 项目,或则 php 项目,那么你只需要在你设定好的

目录下放一个 index.html 即可,以便后续测试。

5.停止httpd 服务

service httpd stop

6.开启httpd 服务

service httpd start

7.验证

访问一级域名:

访问二级域名:

app.beijingdesigner.com

app.beijingdesigner.com

访问二级级域名:

contact.beijingdesigner.com

contact.beijingdesigner.com

好了,以上就是httpd的实现方式,后面我们循序渐进,给大家讲nginx实现方式。

标签: #apache二级域名重