How to Fix 502 Bad Gateway Error in CWP User Panel After Domain Migration

cwp fixes

STAY IN TOUCH

We always have exciting things to talk about and we don’t want you to miss a single thing

Problem Overview

When you migrate a domain from one server to another but leave the original user account intact on the old CWP (CentOS Web Panel) server, you may encounter a 502 Bad Gateway error with “cwpsrv” displayed when trying to access that user’s control panel.

This occurs because the cwpsrv (CWP’s web server) configuration still references the old domain’s proxy settings and backend services that no longer exist on the server. The configuration expects certain services or resources to be available for the domain, but since the domain has been moved, those references become broken, resulting in the 502 error.

Understanding the Issue

CWP uses cwpsrv as its internal web server to handle user panel requests. When a domain is properly hosted on the server, cwpsrv has the correct configuration to proxy requests to the appropriate backend services. However, when you:

  1. Move a domain to another server
  2. Leave the user account on the old server
  3. Don’t update the cwpsrv configuration

The result is a mismatch between what cwpsrv expects and what actually exists, causing the gateway error.

The Solution

The fix is straightforward: rebuild the cwpsrv configuration for the affected user account. This regenerates the configuration files with the current state of the user’s domains and services.

Step-by-Step Fix

Step 1: Rebuild the user’s cwpsrv configuration

/usr/local/cwpsrv/htdocs/resources/scripts/cwpsrv_rebuild_user_conf username

Replace username with the actual CWP username experiencing the issue.

Step 2: Restart the cwpsrv service

systemctl restart cwpsrv

Step 3: Test access

Try logging into the user panel again. The 502 error should now be resolved.

Alternative Solutions

If rebuilding the configuration doesn’t work, here are additional troubleshooting steps:

Check cwpsrv Status

systemctl status cwpsrv

Ensure the service is running properly.

Review User Configuration

cat /usr/local/cwpsrv/conf.d/users/username.conf

This lets you see what configuration exists for the user and identify any problematic entries.

Check cwpsrv Logs

tail -f /usr/local/cwpsrv/logs/error_log

Review the logs while attempting to access the user panel to see specific error messages.

Temporarily Disable User Configuration

If you need immediate access and the rebuild doesn’t work:

mv /usr/local/cwpsrv/conf.d/users/username.conf /usr/local/cwpsrv/conf.d/users/username.conf.bak
systemctl restart cwpsrv

This temporarily removes the problematic configuration. You can restore it later or regenerate it properly.

Prevention

To avoid this issue in the future:

  1. Remove domains properly before migration using CWP’s domain management interface
  2. Delete user accounts if they’re no longer needed after migration
  3. Rebuild configurations after any major changes to user accounts or domains
  4. Use CWP’s migration tools when available to ensure proper cleanup

When to Delete the User Account

If the user account is no longer needed on the old server (all domains have been migrated), consider removing it entirely:

# From CWP root panel: User Accounts → List Accounts → Delete

Or check available removal scripts:

ls -la /scripts/ | grep remove

Conclusion

The 502 Bad Gateway error in CWP user panels after domain migration is a configuration mismatch issue that’s easily resolved by rebuilding the cwpsrv configuration for the affected user. The cwpsrv_rebuild_user_conf script regenerates the proper configuration based on the current state of the server, eliminating references to migrated or removed domains.

This is a common scenario in server administration when domains are moved between servers, and knowing the quick fix can save significant troubleshooting time.

Skip to content