【问题标题】:Proxy pass an application from a different machine to an apache web server代理将应用程序从另一台机器传递到 apache Web 服务器
【发布时间】:2019-09-01 14:46:30
【问题描述】:

我正在运行三个应用程序,其中 2 个在安装了 Apache 的本地机器/服务器上,1 个在不同的机器/服务器上。 我在 Ubuntu 18.04 上使用 Apache2.4

application 1(yii) = 127.0.0.1:80 
application 2(mantis bt) = 127.0.0.1:8080
application 3(yii) = 192.168.X.X:80

我想配置我的 apache Web 服务器以在 https 上托管三个应用程序。我代理通过了 app2 和 app3。

app2 = /app2 http://127.0.0.1:8080
app3 = /app3 http://192.168.X.X

app1可以正常访问成功, app2和app3可以访问,但是找不到.css、.js等文件,报404错误。

注意:我可以在不使用代理通行证时访问所有三个应用程序。

还可以托管这三个应用程序并拥有如下网址:
https://app1.example https://app2.example https://app2.example

我是 apache 新手。请帮我。

【问题讨论】:

    标签: apache2.4


    【解决方案1】:

    请检查我的配置如下: DocumentRoot /var/www/html/app1 错误日志 /var/log/httpd/app1_log 日志级别调试

    <Directory /var/www/html/app1>
    AllowOverride none
    Order allow,deny
    Allow from all
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    # use mod_rewrite for pretty URL support
    RewriteEngine on
    # If a directory or a file exists, use the request directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Otherwise forward the request to index.php
    RewriteRule . index.php
    </Directory>
    
    ProxyRequests Off
    ProxyVia Off
    ProxyPreserveHost On
    
    <Proxy *>
    AddDefaultCharset off
    Order deny,allow
    Allow from all
    </Proxy>
    
    <Location /app2>
        ProxyPass http://127.0.0.1:8080/login_page.php
        ProxyPassReverse http://1127.0.0.1:8080/login_page.php
        SetEnv              proxy-sendchunks 1
    </Location>
    
    <Location /app3>
        ProxyPass http://192.168.X.X/
        ProxyPassReverse http://192.168.X.X/
        SetEnv              proxy-sendchunks 1
    </Location>
    
    <Location /static/>
       ProxyPass !
    </Location>
    </VirtualHost>
    <VirtualHost *:443>
      SSL Configuration
    </VirtualHost> 
    

    【讨论】:

      【解决方案2】:

      如下配置apache虚拟主机

      对于 app2

      <Virtualhost *:80>
           ServerName app2.domain.com
           ServerAdmin youremail@email.com
      
           ProxyPass http://127.0.0.1:8080/
           ProxyPassReverse http://127.0.0.1:8080/
      </Virtualhost *:80>
      

      对于app3

      <Virtualhost *:80>
           ServerName app3.domain.com
           ServerAdmin youremail@email.com
      
           ProxyPass http://192.168.X.X/
           ProxyPassReverse http://192.168.X.X/
      </Virtualhost *:80>
      

      为两个域创建一个单独的虚拟主机。

      创建虚拟主机后重启apache

      service apache2 restart
      

      它对我有用,我希望它对你有用并加载 .css、.js 和其他文件。

      如果你想将aap3重定向到https,那么你最终的虚拟主机文件将如下配置:

      <Virtualhost *:80>
           ServerName app2.domain.com
           ServerAdmin youremail@email.com
      
           ProxyPass http://127.0.0.1:8080/
           ProxyPassReverse http://127.0.0.1:8080/
      </Virtualhost *:80>
      
      <Virtualhost *:80>
           ServerName app3.domain.com
           Redirect / https://app3.domain.com/
      </Virtualhost *:80>
      
      <IfModule mod_ssl.c>
      <VirtualHost *:443>
           ServerName app3.domain.com
           ServerAdmin youremail@email.com
      
           ProxyPass http://192.168.X.X/
           ProxyPassReverse http://192.168.X.X/
      
           Include /etc/letsencrypt/options-ssl-apache.conf
           ServerAlias app3.domain.com
           SSLCertificateFile /etc/letsencrypt/live/app3.domain.com/fullchain.pem
           SSLCertificateKeyFile /etc/letsencrypt/live/app3.domain.com/privkey.pem
      </VirtualHost>
      </IfModule> 
      

      【讨论】:

      • 非常感谢@Subhash。现在它正在工作。现在我必须将对我网站的所有访问重定向到 https。我也必须制作三个 吗?或者有没有办法在一个配置中重定向所有这些?谢谢。
      • 嗨@Subhash,我还有一个问题,正如我在设置中所说的那样,我有两台机器,它们在 1 个公共 IP 上共享,当我尝试将所有访问重定向到 app3(我proxy_pass) 到 https,显示的页面是 app1。请帮忙。谢谢。
      • @carlbasabe 请检查我的答案我为 app3 https 重定向添加配置。
      • 嗨@Subhash,我试过你的配置,但它仍然没有重定向到https,我必须编辑app3的.htaccess吗?谢谢
      猜你喜欢
      • 2014-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-20
      • 1970-01-01
      • 1970-01-01
      • 2015-04-01
      • 1970-01-01
      相关资源
      最近更新 更多