4

Mod_Proxy と Mod_SSL を使用して Apache 2.2.15 を構成し、RHEL 6.3 で CherryPy Web アプリケーションを提供しています。私が苦労しているのは、Web サイトの静的コンテンツ (*.js、*.css、*.jpg) を Apache に提供させることだけです。これが私のVirtualHostエントリです...

<VirtualHost mydomain.com:443>
ServerAdmin support@mydomain.com
ServerName mydomain.com
ProxyPreserveHost On
SSLProxyEngine On
DocumentRoot /var/www/html/mydomain

SSLEngine on
SSLCertificateKeyFile /etc/ssl/myserver.key
SSLCertificateFile /etc/ssl/mydomain_com.crt
SSLCertificateChainFile /etc/ssl/mydomain_com.ca-bundle

# this prevents the follow URL path from being proxied
ProxyPass static/ !

# setup the proxy
<Proxy *>
    Order allow,deny
    Allow from all
</Proxy>
ProxyPass / http://www.mydomain.com:8080/
ProxyPassReverse / http://www.mydomain.com:8080/
</VirtualHost>

たとえば、私のcssファイルへのパスは次のとおりです...

/var/www/html/mydomain/static/style.css

に移動するときにサイト全体を強制的に https にするため

https://www.mydomain.com/static/style.css

また

http://www.mydomain.com/static/style.css

ブラウザに、ページが見つからない (404) と表示されます。誰かが私が間違っていることを見ることができますか?

編集: Apache はまだ /static をプロキシしているようです... Apache アクセス ログで /static/style.css にアクセスすると、このリダイレクトが見つかりました...

xxx.xxx.xxx.xxx - - [17/Sep/2012:08:46:06 -0400] "GET /static/style.css HTTP/1.1" 301 337 "https://www.mydmain.com/Home/" "Mozilla/5.0 (X11; Linux x86_64; rv:10.0.7) Gecko/20120826 Firefox/10.0.7"

なぜそれが起こっているのか誰か知っていますか?

前もって感謝します!

アンドリュー

4

2 に答える 2

1

静的ファイルが「メイン」ソース フォルダーの下にある場合は、CherryPy にスタイルシート、画像、js などの特定のフォルダーを提供するように指示することをお勧めします。

個人的には、構成を生成し、アプリケーションをマウントするときにその構成を使用します。

app = cherrypy.tree.mount(Root(), script_name="", config=somefile.get_config())

CherryPy で提供される静的ファイルの例。

  • これ/cssは、テンプレートまたは HTML 内から使用するパスです。
  • os.path.abspath(os.path.join(os.path.dirname(__file__)、インデックス ファイル (または、インデックス内から quickstart() を開始しない場合は他のスクリプト) を指すパスを生成します。
  • 上記のパスの後に、静的コンテンツ フォルダーへの相対パスが続きます。

ファイル:

##somefile
def get_config():
    return {
        '/':
        {
            'tools.encode.on': True,
            'tools.encode.encoding': 'UTF-8'
        },
        '/css':
        {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': os.path.abspath(os.path.join(os.path.dirname(__file__), 'relative/path/to/your/css/folder'))
        },
        '/js':
        {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': os.path.abspath(os.path.join(os.path.dirname(__file__), 'relative/path/to/your/js/folder'))
        }
    }
于 2012-12-14T13:03:30.897 に答える