باستخدام proxypass للحصول على الصفحات ولكن ليس الصور

StackOverflow https://stackoverflow.com/questions/569861

سؤال

نتيجة ل أخطاء فظيعة، فظيعة, ، لقد غيرنا كيف نتصل Apache إلى Tomcat. كنا نستخدمها mod_jk:

JkMount /path ajp13

الآن نحن نستخدم mod_proxy_ajp:

ProxyPass /path ajp://localhost:8009/path
ProxyPassReverse /path ajp://localhost:8009/path

ومع ذلك، هناك ميزة JkMount عرضت ولكن ProxyPass لا: القدرة على تحديد أنواع الملفات. هذا جعل من الممكن لملفات HTML الوكيل، ولكن ليس الصور - بمعنى آخر، للسماح لأباخ سريع لطيف تخدم الأشياء الثابتة، واللجوء إلى Tomcat البطيء فقط للأشياء الديناميكية.

JkMount /*.html ajp13

هل هناك أي طريقة لتحقيق هذا مع ProxyPassب ربما باستخدام محيط <Location> التوجيه أو شيء من هذا القبيل؟

هل كانت مفيدة؟

المحلول

يستخدم proxypassMatch.:

ProxyPassMatch ^/(path/.*\.html)$ ajp://localhost:8009/$1

تم التعديل: تصحيح Marcus Downing

نصائح أخرى

ليس مشكلتك ولكن شيء لمشاهدة لاستخدام هذا التكوين. أثناء استخدام Apache MOD_PROXY للاتصال ب Tomcat كان سجل الأخطاء الخاص بي يتم إظهار الاتصالات المسقطة تحت الحمل المعتدل. إضافة هذا إلى httpd.conf حل مشاكلي.

SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1

وظيفة KMKAKLAN هي الإجابة الصحيحة، لكنها أعطتني الخطأ:

Syntax error on line 32 of .../httpd-vhosts.conf:
ProxyPass Unable to parse URL

عملت عندما غيرت التوجيه لقراءة:

ProxyPathMatch ^/(path/.*\.html)$ ajp://localhost:8009/$1

لا أستطيع إلا أن أفترض أن وضع $1 بجانب رقم المنفذ 8009 كان يربك ذلك.

نستخدم ما يلي للسماح ل Apache بمخدم الصور وتعيين رؤوس انتهاء الصلاحية المعقولة:

<Virtualhost *:80>
    ServerName domain.com
    ServerAlias *.domain.com

    Alias /img/ /var/www/domain/img/
    <Directory /var/www/domain/img/>
        ExpiresActive On
        ExpiresByType image/gif "access plus 1 months"
        ExpiresByType image/jpg "access plus 1 months"
        ExpiresByType image/jpeg "access plus 1 months"
        ExpiresByType image/png "access plus 1 months"
        ExpiresByType image/x-icon "access plus 1 months"
        ExpiresByType image/ico "access plus 1 months"
        # This will prevent apache from having to check for a .htaccess file on each request.
        AllowOverride None
        # Allow symlinks. Otherwise, apache will make a separate call on each filename to ensure it is not a symlink.
        Options +FollowSymLinks -SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    # Prevent domain.com/img from being served by Tomcat
    ProxyPass /img !

    # Pass all other requests to Tomcat
    ProxyPass / ajp://localhost:8009/

    # 1. Note that usually no ProxyPassReverse directive is necessary. The AJP request includes
    #    the original host header given to the proxy, and the application server can be expected to
    #    generate self-referential headers relative to this host, so no rewriting is necessary. 
    # 2. If you still want to use it, read this first:
    #    http://www.humboldt.co.uk/2009/02/the-mystery-of-proxypassreverse.html
    # ProxyPassReverse / http://domain.com/
</Virtualhost>

ومع ذلك، كما ترون، نقوم بتخزين الصور خارج تطبيق Tomcat لدينا. لا أعرف إذا كان يعمل أيضا في الصور داخل التطبيق.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top