Zimbra uses Nginx as its proxy, and you can configure Nginx to block direct access via the server’s IP address. Here’s how to configure it:
Edit Nginx Configuration for Web Access:
sudo nano /opt/zimbra/conf/nginx/includes/nginx.conf.web.https.default
Add Server Block to Deny IP-Based Access: Add a new server block at the top of the configuration to deny access via the server’s IP.
server { listen 80; listen 443 ssl; server_name <em>; # This matches any request not using a domain name (IP-based access) return 444; # Return a 444 response (which drops the connection without sending a response) }
Example: Conditional Logic with if in Nginx
Using if for Conditional Redirect or Block You can use the if directive to match specific conditions, such as the client’s IP address, and act accordingly.
For example, you can block access based on an IP or redirect based on conditions:
server { listen 80; server</em>name mail.example.com; # Block access if the request is made to the server IP if ($host = '1.2.3.4') { # Replace 1.2.3.4 with your server IP return 444; # Drop the connection for IP access } # Allow access if using the domain name if ($host = 'mail.example.com') { # Normal handling for mail.example.com # Add proxy_pass, root, or other configs here } # Default behavior return 403; # Deny any other requests }
Restart Zimbra Proxy: Once you’ve made the changes, restart the Zimbra proxy to apply the new configuration:
zmproxyctl restart