Changing Magento Admin URL and Port when Running Varnish
If you’ve installed Varnish on your server for Magento, you might find that some backend features fail to work because the URL and port have changed. In this guide, we’ll walk through how to correct these issues step-by-step.
Understanding the Problem
When you install Varnish, it typically runs on port 80 (or 443 for SSL), while Magento shifts to a different port, often 8080. As a result, your admin URL becomes www.mystore.com:8080/admin instead of www.mystore.com/admin.
Many features rely on this correct connection string. In your case, the print packing slip functionality fails because it can’t reach the backend server at the new port. Changing the port in frontend JavaScript is a quick fix, but not sustainable for all features.
Changing the Magento Admin URL and Port
To resolve this issue permanently:
-
Update your Varnish configuration file (usually /etc/varnish/varnish.conf):
# Change the backend host to match your Magento server backend default { .host = "127.0.0.1"; .port = "8080"; } -
Configure Varnish to pass requests for the admin URL to Magento directly:
# Add this section at the end of your varnish.conf acl admin { if (req.url ~ "^/admin/") { return (pass); } } vcl 403 { if (-Beresp.status == 403) { set obj.http.Content-Type = "text/html; charset=utf-8"; set obj.body = "Forbidden"; return (synth(403,obj)); } } -
Update your Magento configuration:
- Navigate to your Magento installation’s app/etc/local.xml or app/etc/env.php file.
- Look for the
<base_url>and<base_media_url>tags under<global>. - Change them from
http://www.mystore.comtohttp://www.mystore.com:8080.
-
Clear your cache:
php bin/magento cache:clean
Important Considerations
- Always backup your files before making changes, especially in the local.xml or env.php files.
- Ensure that your firewall allows traffic on port 8080.
- If you use SSL, update the backend host and port to reflect your secure connection details.
Conclusion
Changing the Magento admin URL and port when running Varnish requires updating both the Varnish configuration and Magento’s core settings. By following these steps, you can ensure that all features work correctly without resorting to manual fixes for each issue.
Remember to test thoroughly after making changes, especially with SSL certificates if applicable. If you need further assistance or find unexpected issues, don’t hesitate to reach out to a professional development team like Laravel Company for detailed support and consultation.
Happy fixing!