JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

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

wys521 2024-09-27 13:47:32 精选教程 30 ℃ 0 评论

前言:

项目测试,部署,我们难免会想着将不同的项目放到不同的目录去访问,或则作为程序员的你,仅仅是为了把妹也好~本文带你简单配置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/conf
vi httpd.conf

完整 httpd.conf 配置如下

ServerRoot "/etc/httpd"
Listen 80
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module modules/libphp5.so
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
#ServerName www.example.com:80
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
AllowOverride None
Require all granted
</Directory>
# Further relax access to the default document root:
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require 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\"" combined
LogFormat "%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 None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
<VirtualHost *:80>
ServerAdmin scqshine@yeah.net
DocumentRoot "/var/www/html"
ServerName www.beijingdesigner.com
ServerAlias www.beijingdesigner.com beijingdesigner.com
DirectoryIndex index.php index.html index.htm
</VirtualHost>
<VirtualHost *:80>
ServerAdmin scqshine@yeah.net
DocumentRoot "/var/www/app"
ServerName app.beijingdesigner.com
ServerAlias app.beijingdesigner.com
DirectoryIndex index.php index.html index.htm
</VirtualHost>
<VirtualHost *:80>
ServerAdmin scqshine@yeah.net
DocumentRoot "/var/www/contact"
ServerName contact.beijingdesigner.com
ServerAlias contact.beijingdesigner.com
DirectoryIndex 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.验证

访问一级域名:

www.beijingdesigner.com

访问二级域名:

app.beijingdesigner.com

访问二级级域名:

contact.beijingdesigner.com

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

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表