How to Fix “Invalid command ‘ProxyPass'” Error in Apache on OpenSUSE


1 views

When attempting to configure reverse proxy in OpenSUSE 13.1's Apache, you encounter the frustrating error:

AH00526: Syntax error on line 4 of /etc/apache2/httpd-proxy.conf:
Invalid command 'ProxyPass', perhaps misspelled or defined by a module not included in the server configuration

The error clearly indicates that while you've loaded the proxy modules, Apache isn't recognizing the ProxyPass directive. This typically occurs due to:

  1. Modules not being properly enabled at the system level
  2. Missing dependencies for proxy modules
  3. Incorrect configuration file inclusion

Here's the full working configuration that resolves the issue:

# First ensure all required modules are properly installed
sudo zypper install apache2-prefork apache2-mod_proxy apache2-mod_proxy_http

# Then enable them correctly
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_connect

# Create a proper virtual host configuration
sudo nano /etc/apache2/vhosts.d/proxy_example.conf

Here's the proper way to structure your proxy configuration:

<VirtualHost *:80>
    ServerName subsite.example.com
    ServerAlias www.example.com/subsite
    
    ProxyPreserveHost On
    ProxyRequests Off
    
    <Proxy *>
        Require all granted
    </Proxy>
    
    ProxyPass / http://localhost:81/
    ProxyPassReverse / http://localhost:81/
    
    ErrorLog /var/log/apache2/subsite_error.log
    CustomLog /var/log/apache2/subsite_access.log combined
</VirtualHost>

After making these changes, verify your configuration:

# Check for syntax errors
apache2ctl configtest

# If everything looks good, restart Apache
sudo systemctl restart apache2

# Check module loading
apache2ctl -M | grep proxy

For newer OpenSUSE versions, consider using the proxy_wstunnel module if you need WebSocket support:

sudo a2enmod proxy_wstunnel

<VirtualHost *:80>
    ProxyPass /ws/ ws://localhost:8080/
    ProxyPassReverse /ws/ ws://localhost:8080/
</VirtualHost>

The error message you're seeing (Invalid command 'ProxyPass') typically indicates that Apache's proxy modules aren't properly loaded, despite running the a2enmod commands. Let's troubleshoot this systematically.

First, check if the proxy modules are actually enabled:

# Check enabled modules
apache2ctl -M | grep proxy

# Alternative method
ls /etc/apache2/mods-enabled/ | grep proxy

If no output appears, the modules aren't loaded. On OpenSUSE, you might need to use a2enmod differently or manually create symlinks.

Your httpd-proxy.conf has a few issues that need addressing:

<VirtualHost *:80>
    ServerName www.site.com
    DocumentRoot /srv/www/subsite
    
    # Proxy configuration
    <Proxy *>
        Require all granted
    </Proxy>
    
    ProxyPass /subsite/ http://localhost:81/
    ProxyPassReverse /subsite/ http://localhost:81/
    
    # Important for proper URL handling
    ProxyPreserveHost On
</VirtualHost>

Here's the full procedure to get ProxyPass working:

# 1. Install required modules (if not present)
sudo zypper install apache2-prefork apache2-mod_proxy apache2-mod_proxy_http

# 2. Enable modules (OpenSUSE specific)
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_connect

# 3. Verify modules are loaded
sudo apache2ctl -t -D DUMP_MODULES | grep proxy

# 4. Create or modify your virtual host file
sudo nano /etc/apache2/vhosts.d/proxy.conf

# 5. Test configuration
sudo apache2ctl configtest

# 6. Restart Apache
sudo systemctl restart apache2

Firewall issues: Ensure port 81 is open if you're proxying to localhost:81

sudo firewall-cmd --add-port=81/tcp --permanent
sudo firewall-cmd --reload

SELinux conflicts: On OpenSUSE with SELinux enabled:

sudo setsebool -P httpd_can_network_connect 1

Add these directives to your virtual host for better debugging:

LogLevel debug
ErrorLog /var/log/apache2/proxy_error.log
CustomLog /var/log/apache2/proxy_access.log combined

Check these logs when troubleshooting connection issues between Apache and your backend service.