国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > Apache > 正文

apache實(shí)現(xiàn)部署多個(gè)網(wǎng)站(一個(gè)ip部署多域名)的方法詳解

2024-08-27 18:30:51
字體:
供稿:網(wǎng)友

前言

在日常的網(wǎng)站發(fā)布中很多情況下都無法做到一個(gè)IP對(duì)應(yīng)一個(gè)站點(diǎn),在IP4的情況下IP的資源是相對(duì)有限的。然而作為最流行的Apache自然也考慮到這種情況,下面來一起看看詳細(xì)的介紹吧。

配置方法

首先apache的版本是2.4.7,然后系統(tǒng)是Ubuntu 14.04.1 LTS。(因?yàn)楹孟衽渲梦募湍夸浻胁町悾?/p>

首先進(jìn)到apache2目錄下,

apache同ip不同域名,apache,部署多個(gè)網(wǎng)站,apache部署網(wǎng)站

我們要探討的主要是sites-available和sites-enabled根據(jù)字面意思,前一個(gè)是網(wǎng)站可用的,后一個(gè)是網(wǎng)站可用的,然后我們還知道了,sites-enabled里面的文件是sites-available里面文件的軟鏈接,所以我們主要改site-available的文件,打開site-available有兩個(gè)文件,但我們只需要000-default.conf文件,打開cat文件

代碼如下:

<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must seothert it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost DocumentRoot /var/www/ # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf</VirtualHost>

這就是網(wǎng)址配置文件了,而我們要修改的只有被注釋掉的ServerName 域名,DocumentRoot 路徑這兩個(gè)部分,去掉注釋剩下。

<VirtualHost *:80> ServerName #這里是域名地址 ServerAdmin webmaster@localhost DocumentRoot /var/www/  #這里是路徑 ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined</VirtualHost>

可以直接添加在下面,重啟apache就成了。但是上面的優(yōu)先級(jí)要更高,訪問自己的域名會(huì)跳轉(zhuǎn)到你設(shè)置的路徑,直接訪問ip還是會(huì)到第一個(gè)設(shè)置的路徑,你也可以選擇刪除。

還有另外一種改法就是新建一個(gè)文件,xxx.conf然后內(nèi)容一樣,

<VirtualHost *:80> ServerName #這里是域名地址 ServerAdmin webmaster@localhost DocumentRoot /var/www/  #這里是路徑 ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined</VirtualHost>

在創(chuàng)建軟鏈接 ln -s ../sites-avaiable/xxx.conf ../sites-enable/xxx.conf

這樣子也可以實(shí)現(xiàn),但是優(yōu)先級(jí)還是000-default.conf高。

好了,就是這么簡單。

附:配置Apache2.4.7反向代理的方法

1.設(shè)置httpd.conf

打開Apache24/conf文件夾下的httpd.conf設(shè)置文件,找到一下幾行把前面的注釋‘#'刪除

LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_connect_modulemodules/mod_proxy_connect.soLoadModule proxy_ftp_modulemodules/mod_proxy_ftp.soLoadModule proxy_http_modulemodules/mod_proxy_http.so

(Ps:很多人都會(huì)注釋LoadModuleproxy_balancer_modulemodules/mod_proxy_balancer.so,然而這個(gè)是做負(fù)載均衡用的一個(gè)功能,單純做反向代理的話,不需要用這個(gè),而且取消了這里的注釋不進(jìn)行相應(yīng)的設(shè)置的話,會(huì)導(dǎo)致apache服務(wù)無法開啟)

然后找到Include conf/extra/httpd-vhosts.conf

這一行前面的注釋‘#'也刪除,引入這個(gè)文件

2.設(shè)置httpd-vhosts.conf

打開Apache24/conf/extra文件夾下的httpd-vhosts.conf.conf找到

<VirtualHost _default_:80>#ServerName www.example.com:80DocumentRoot "${SRVROOT}/htdocs"</VirtualHost>

在后面添加

ProxyRequests OffProxyPass /***(你想要訪問的地址) http://*******(想要代理的地址)ProxyPassReverse /***(你想要訪問的地址) http://*******(想要代理的地址)

比如說我想在瀏覽器中輸入localhost,但實(shí)際獲取的內(nèi)容是www.baidu.com的話就可以設(shè)置為ProxyPass /***(你想要訪問的地址) http://*******(想要代理的地址),第二個(gè)ProxyPassReverse是做域名重定向使用的,如果你代理的那個(gè)地址重定向的跳到另一個(gè)地方,有了ProxyPassReverse的設(shè)置就可以相應(yīng)的跳轉(zhuǎn)過去 沒有的話可能就會(huì)報(bào)錯(cuò)

如果想讓別的電腦訪問自己電腦的外網(wǎng)地址就可以訪問自己服務(wù)器可以設(shè)置一下httpd.conf中的<Directory "${SRVROOT}/htdocs">

Require all denied改為Require all granted允許所有的請求和訪問

然后就可以使用了~

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對(duì)VEVB武林網(wǎng)的支持。


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 孝感市| 绵阳市| 大田县| 铁岭市| 泸西县| 开阳县| 龙南县| 安福县| 祁连县| 兴安县| 湟中县| 申扎县| 萍乡市| 恩平市| 丰都县| 娄底市| 三江| 固镇县| 沈阳市| 前郭尔| 阿尔山市| 阳谷县| 四平市| 朝阳区| 于田县| 广昌县| 镇宁| 大丰市| 开封市| 茶陵县| 阿城市| 涿鹿县| 九台市| 曲沃县| 台南县| 靖远县| 金乡县| 汕头市| 土默特左旗| 盘锦市| 双柏县|