Apache反向代理问题

时间:2016-12-30 12:42:37

标签: apache reverse-proxy transmission

我有一个apache服务器和传输守护进程一起运行。 只有端口80和443打开,我希望能够从" https://address.net/transmission"访问传输的网络界面。而不是" localhost:9091"

我遵循了几个指南,但我无法使其工作(ERR_CONNECTION_REFUSED或502),这是我的最后一个配置。谢谢。

apache2.conf:

Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory /path/apache>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>


<Directory /path/apache/private>
        AuthType Basic
        AuthName "Restricted Content"
        AuthUserFile /path/.htpasswd
        Require valid-user
</Directory>

AccessFileName .htaccess
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

ports.conf:

Listen 80
Listen 443

proxy.conf:

<IfModule mod_proxy.c>
    ProxyRequests Off
    ProxyPreserveHost On
    <Proxy *>
        AddDefaultCharset off
        Order deny,allow
            Allow from all
    </Proxy>

        ProxyPass /transmission https://localhost:9091
        ProxyPassReverse /transmission https://localhost:9091

    ProxyVia On

</IfModule>

/sites-enabled/000-default.conf:

<VirtualHost *:80>
    ServerName address.net

    DocumentRoot /path/apache

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


        Redirect permanent / https://address.net/

</VirtualHost>

/sites-enabled/default-ssl.conf:

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>

        ServerName address.net
        DocumentRoot /path/apache


        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined


        SSLEngine on

        SSLCertificateFile  /stuff.pem
        SSLCertificateKeyFile /morestuff.pem


        SSLProxyEngine on

        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                SSLOptions +StdEnvVars
        </Directory>

        BrowserMatch "MSIE [2-6]" \
                nokeepalive ssl-unclean-shutdown \
                downgrade-1.0 force-response-1.0
        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

    </VirtualHost>
</IfModule>

2 个答案:

答案 0 :(得分:0)

也许

    ProxyPass /transmission https://localhost:9091
    ProxyPassReverse /transmission https://localhost:9091

应该是:

    ProxyPass /transmission http://localhost:9091
    ProxyPassReverse /transmission http://localhost:9091

答案 1 :(得分:0)

对我有用的设置(Debian jessie + apache2)。使用letencrypt(SSL / TLS)永久重定向到443后,我在连接到webgui时遇到问题。首先,我需要在Apache中启用代理模块:

JSONObject openingObject = resultObject.getJSONObject("opening_hours");  

然后,我必须编辑/etc/apache2/mods-available/proxy.conf文件。但是在此之前,我像这样备份proxy.conf文件:

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo systemctl restart apache2

现在,我创建一个名为proxy.conf的新文件,并在其中添加以下几行:

cd /etc/apache2/mods-available
sudo mv proxy.conf proxy.conf.default

ProxyPass和ReverseProxyPass行创建了传输Apache代理(实际上是反向代理)。重定向语句(可选)将http连接永久重定向到https连接,以确保安全。重新启动apache:

<ifmodule mod_proxy.c>
  #turning ProxyRequests on and allowing proxying from all may allow
  #spammers to use your proxy to send email.

  ProxyRequests Off
  <proxy *>
    AddDefaultCharset off
    Order Allow,Deny
    Allow from all
  </proxy>

  ProxyPass /transmission http://localhost:9091/transmission
  ProxyPassReverse /transmission http://localhost:9091/transmission
  # Line below is optional
  Redirect permanent /transmission https://myserver.com/transmission/web/

  # Enable/disable the handling of HTTP/1.1 "Via:" headers.
  # ("Full" adds the server version; "Block" removes all outgoing Via: headers)
  # Set to one of: Off | On | Full | Block

  ProxyVia On
</ifmodule>

现在您应该可以使用来访问传输Web界面

https://myserver.com/transmission

我遇到409冲突的情况。试试

https://myserver.com/transmission/web/