重定向Apache上的端口


Redirect ports on Apache

我在机器上安装了以下设置:

  • Ubuntu 14.04 Lts服务器
  • Apache

但我有两个web应用程序在我的服务器上运行,它们是:

  • Phpipam(在端口80上运行)
  • Ethercalc(在端口8000上运行)
  • Apache(在端口80上运行)

我最近不得不使用ProxyReverso将Ethercalc重定向到80。于是我的设置:

<VirtualHost *:80>
        ProxyPreserveHost On
    ServerName localhost
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/
    ProxyRequests Off 
    ProxyPass / http://192.168.1.32:8082/
    ProxyPassReverse / http://192.168.1.32:8082/
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order Allow,deny
Allow from all
</Directory>
<Location /teste>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
AuthUserFile /etc/apache2/site1/.htpasswd
AuthName "Password Protected Area"
AuthType Basic
Require valid-user
</Location>
<Location /teste/edit>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Deny from all
Allow from 192.168.12.31
</Location>
<Directory /var/www/phpipam>
Options FollowSymLinks
AllowOverride all
Require all granted
</Directory>
    # 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

</VirtualHost>

当访问我的localhost时,它会重定向到Ethercalc,但当我键入例如:https://localhost:81,我被重定向到Phpipam。

有人知道这是否可能吗?

您可以使用两个虚拟主机,但不必使用端口号。您通常有两个IP地址可供使用,即127.0.0.1和127.0.0.1.1。一个用于PHPiPam,另一个用于EtherCalc。那么你就不必使用代理了。

现在您正在将所有请求重定向到Ehtercalc。您只需要对以www.ethercalc.te.开头的请求执行此操作

您在/etc/hosts文件中设置了两个域(www.ethercalc.te和www.phpipam.te),为它们创建了两个虚拟主机,启用它们,就可以开始了。

在Apache中,您有一个port.conf。在该文件中,您可以添加端口81作为Apache应该侦听的端口。您可以为端口81创建一个虚拟主机,然后将其映射到PHPipam服务器。

在我的文件/etc/hosts中,我已将第一个条目设置为:127.0.0.1 localhost www.tandt.lb tandt.lb

这是虚拟主机:

<VirtualHost www.tandt.lb:80>
    ServerName www.tandt.lb
    ServerAlias tandt.lb *.tandt.lb
    ServerAdmin lbergman@tandt.lb
    DocumentRoot /var/www/Websites/TestAndTools
    RewriteEngine On
    RewriteOptions Inherit

    <Directory /var/www/Websites/TestAndTools>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride FileInfo
        Order allow,deny
        allow from all
    </Directory>
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/tandt/error.log
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel debug
    CustomLog ${APACHE_LOG_DIR}/tandt/access.log combined
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

在使用a2ensite…启用此虚拟目录之前,请确保创建自定义日志目录。。。。(/etc/apache/sites目录中的文件名可用)。