Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»Excluding URLs from ProxyPass in Apache

    Excluding URLs from ProxyPass in Apache

    By RahulJanuary 24, 20232 Mins Read

    Apache’s mod_proxy module allows you to forward requests to another server using the ProxyPass and ProxyPassReverse directives. However, in some cases, you may want to exclude certain URLs from being proxied. In this tutorial, I will show you how to exclude an URL from ProxyPass in Apache.

    Advertisement

    The first step is to identify the URL that you want to exclude from being proxied. For this tutorial, let’s assume that we want to exclude the URL “/static” from being proxied.

    Exclude URL in Apache ProxyPass

    Apache proxy sends the requests to backend listeners. In some cases, you may need to execute URLs to be proxied. For example. you have some static content that is stored under the “/var/www/html/static”. The application serves the static content, which URLs begin with “/static”. You wanted to service all the URLs that begin with “/static” should be directly served from the directory without proxying them.

    You can do this by adding the following configuration before the main ProxyPass settings.

    1
    2
    ProxyPass /static !
    Alias "/static" "/var/www/html/static"

    The ! symbols tell apache, not to proxy requests that are beginning with the “/static” sub url. The Alias map URLs to the “/var/www/html/static” directory.

    Make sure that the above configuration is added before the ProxyPass configuration. A sample virtual host looks like the below:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <VirtualHost *:80>
        ServerName example.com
     
        ProxyPass /static !
        Alias "/static" "/var/www/html/static"
     
        <Directory "/var/www/html">
            Require all granted
        </Directory>
     
        ProxyPreserveHost On
        ProxyPass /  http://127.0.0.1:8080/
        ProxyPassReverse /  http://127.0.0.1:8080/
    </VirtualHost>

    Make the required changes in Apache virtual host configuration and restart the Apache service. To test the configuration, access the URL that you excluded from the proxy, in this case, it would be “/static”. If the configuration is correct, you should see the content of your website, instead of being proxied to the backend server.

    Conclusion

    In conclusion, the mod_proxy Apache module also provides an option to execute the URLs to be proxied. That can be helpful for serving static content directly from the web server instead of proxying them to the backend server. In this tutorial, we have provided you the instructions with an example, to exclude the URLs from ProxyPass in the Apache web server. Remember to test your configuration after making any changes to ensure it is working as expected.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Configure Postfix to Use Gmail SMTP on Ubuntu & Debian

    Deploying Flask Application on Ubuntu (Apache+WSGI)

    OpenSSL: Working with SSL Certificates, Private Keys and CSRs

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Configure Postfix to Use Gmail SMTP on Ubuntu & Debian
    • PHP Arrays: A Beginner’s Guide
    • Deploying Flask Application on Ubuntu (Apache+WSGI)
    • OpenSSL: Working with SSL Certificates, Private Keys and CSRs
    • How to Create and Read List in Python
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.