|
| 1 | +--- |
| 2 | +title: "Fix Clash VPN Mixed Content Errors" |
| 3 | +lang: en |
| 4 | +layout: post |
| 5 | +audio: false |
| 6 | +translated: false |
| 7 | +generated: true |
| 8 | +--- |
| 9 | + |
| 10 | +The error messages you're encountering indicate a **mixed content** issue with the Clash VPN application, specifically when the page at `https://clash.razord.top/` tries to load resources from an insecure `http://127.0.0.1:9090/` endpoint (e.g., `http://127.0.0.1:9090/version`). Modern browsers block such requests because they violate security policies by attempting to load insecure HTTP content on a secure HTTPS page. Additionally, there are CORS (Cross-Origin Resource Sharing) errors due to access control restrictions. Below is a step-by-step guide to resolve this issue. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +### Why This Happens |
| 15 | +- **Mixed Content Error**: The webpage is served over HTTPS, but it’s attempting to fetch resources (like the version check) from `http://127.0.0.1:9090`, which is insecure. Browsers block these requests to prevent potential security vulnerabilities, such as man-in-the-middle attacks. |
| 16 | +- **CORS Error**: The browser is blocking the request to `http://127.0.0.1:9090` due to CORS policy, which restricts cross-origin requests unless explicitly allowed by the server. |
| 17 | +- **Clash Context**: Clash (or Clash for Windows) is a proxy application that likely uses a local server (`127.0.0.1:9090`) for its dashboard or API. If this local server doesn’t support HTTPS or isn’t configured correctly, it triggers these errors when accessed via an HTTPS webpage. |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +### Steps to Fix the Issue |
| 22 | + |
| 23 | +#### 1. **Verify Clash Core Configuration** |
| 24 | + - **Check if Clash Core is Running**: Ensure the Clash core (the backend service) is running on your machine and listening on `127.0.0.1:9090`. You can verify this by: |
| 25 | + - Opening a terminal or command prompt. |
| 26 | + - Running `curl http://127.0.0.1:9090/version` to check if the endpoint responds with the Clash version. |
| 27 | + - If it doesn’t respond, ensure the Clash service is active. Restart Clash for Windows or the Clash core process. |
| 28 | + - **Enable HTTPS for Clash Core** (if possible): |
| 29 | + - Some versions of Clash (e.g., Clash Premium or Clash Meta) support HTTPS for the local API. Check the Clash documentation or configuration file (usually `config.yaml`) for an option to enable HTTPS for the external controller (the API endpoint). |
| 30 | + - Look for a setting like `external-controller` or `external-ui` in the configuration file. For example: |
| 31 | + ```yaml |
| 32 | + external-controller: 127.0.0.1:9090 |
| 33 | + external-ui: <path-to-ui> |
| 34 | + ``` |
| 35 | + If HTTPS is supported, you may need to configure a certificate for the local server. This is advanced and may require generating a self-signed certificate (see step 4 below). |
| 36 | +
|
| 37 | +#### 2. **Access the Dashboard via HTTP (Temporary Workaround)** |
| 38 | + - If the Clash dashboard can be accessed via HTTP (e.g., `http://clash.razord.top/` instead of HTTPS), try loading it without HTTPS to avoid mixed content issues: |
| 39 | + - Open your browser and navigate to `http://clash.razord.top/`. |
| 40 | + - Note: This is not recommended for production use, as HTTP is insecure. Use this only for testing or if the dashboard is only accessed locally. |
| 41 | + - If the dashboard requires HTTPS, proceed to the next steps to address the root cause. |
| 42 | + |
| 43 | +#### 3. **Update URLs to HTTPS** |
| 44 | + - The error suggests the Clash dashboard is trying to fetch resources from `http://127.0.0.1:9090`. If you have access to the Clash dashboard’s source code or configuration: |
| 45 | + - Check the frontend code (e.g., `index-5e90ca00.js` or `vendor-827b5617.js`) for hardcoded `http://127.0.0.1:9090` references. |
| 46 | + - Update these to `https://127.0.0.1:9090` if the Clash core supports HTTPS, or use a relative URL (e.g., `/version`) to let the browser use the same protocol as the page. |
| 47 | + - If you don’t have access to the source code, you may need to configure a reverse proxy (see step 4). |
| 48 | + |
| 49 | +#### 4. **Set Up a Reverse Proxy with HTTPS** |
| 50 | + - To resolve the mixed content issue, you can set up a reverse proxy (e.g., using Nginx or Caddy) to serve the Clash core API (`http://127.0.0.1:9090`) over HTTPS. This allows the dashboard to communicate with the core securely. |
| 51 | + - **Steps for Nginx**: |
| 52 | + 1. Install Nginx on your system (if not already installed). |
| 53 | + 2. Generate a self-signed SSL certificate for `127.0.0.1`: |
| 54 | + ```bash |
| 55 | + openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout localhost.key -out localhost.crt -subj "/CN=localhost" |
| 56 | + ``` |
| 57 | + 3. Configure Nginx to proxy requests to `http://127.0.0.1:9090` over HTTPS. Create a configuration file (e.g., `/etc/nginx/sites-available/clash`): |
| 58 | + ```nginx |
| 59 | + server { |
| 60 | + listen 443 ssl; |
| 61 | + server_name localhost; |
| 62 | +
|
| 63 | + ssl_certificate /path/to/localhost.crt; |
| 64 | + ssl_certificate_key /path/to/localhost.key; |
| 65 | +
|
| 66 | + location / { |
| 67 | + proxy_pass http://127.0.0.1:9090; |
| 68 | + proxy_set_header Host $host; |
| 69 | + proxy_set_header X-Real-IP $remote_addr; |
| 70 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 71 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 72 | + } |
| 73 | + } |
| 74 | + ``` |
| 75 | + 4. Enable the configuration and restart Nginx: |
| 76 | + ```bash |
| 77 | + sudo ln -s /etc/nginx/sites-available/clash /etc/nginx/sites-enabled/ |
| 78 | + sudo nginx -t |
| 79 | + sudo systemctl restart nginx |
| 80 | + ``` |
| 81 | + 5. Update the Clash dashboard to use `https://localhost:443` instead of `http://127.0.0.1:9090` for API requests. |
| 82 | + 6. In your browser, accept the self-signed certificate when prompted. |
| 83 | + |
| 84 | + - **Alternative with Caddy**: Caddy is simpler to configure and automatically handles HTTPS: |
| 85 | + 1. Install Caddy. |
| 86 | + 2. Create a `Caddyfile`: |
| 87 | + ```caddy |
| 88 | + localhost:443 { |
| 89 | + reverse_proxy http://127.0.0.1:9090 |
| 90 | + } |
| 91 | + ``` |
| 92 | + 3. Run Caddy: `caddy run`. |
| 93 | + 4. Update the Clash dashboard to use `https://localhost:443`. |
| 94 | + |
| 95 | +#### 5. **Bypass CORS Restrictions (Advanced)** |
| 96 | + - The CORS error (`XMLHttpRequest cannot load http://127.0.0.1:9090/version due to access control checks`) indicates the Clash core server isn’t sending the appropriate CORS headers. If you control the Clash core: |
| 97 | + - Modify the Clash core configuration to include CORS headers, such as: |
| 98 | + ```yaml |
| 99 | + external-controller: 127.0.0.1:9090 |
| 100 | + allow-cors: true |
| 101 | + ``` |
| 102 | + (Check the Clash documentation for the exact syntax, as this depends on the Clash version.) |
| 103 | + - Alternatively, the reverse proxy setup in step 4 can handle CORS by adding headers like: |
| 104 | + ```nginx |
| 105 | + add_header Access-Control-Allow-Origin "https://clash.razord.top"; |
| 106 | + add_header Access-Control-Allow-Methods "GET, POST, OPTIONS"; |
| 107 | + add_header Access-Control-Allow-Headers "*"; |
| 108 | + ``` |
| 109 | + - If you don’t control the core, you can use a browser extension to temporarily bypass CORS (e.g., “CORS Unblock” for Chrome), but this is not recommended for security reasons. |
| 110 | + |
| 111 | +#### 6. **Update Clash or Switch to a Compatible Version** |
| 112 | + - Ensure you’re using the latest version of Clash for Windows or Clash Verge, as older versions may have bugs or lack HTTPS support for the external controller. |
| 113 | + - Check the Clash GitHub repository (`github.com/Dreamacro/clash` or `github.com/Fndroid/clash_for_windows_pkg`) for updates or reported issues related to mixed content or CORS. |
| 114 | + - Consider switching to **Clash Verge** or **Clash Meta**, which may have better support for HTTPS and modern browser security policies.[](https://clashverge.net/en/tutorial-en/) |
| 115 | + |
| 116 | +#### 7. **Allow Insecure Content in Browser (Not Recommended)** |
| 117 | + - As a last resort, you can allow insecure content in your browser for `https://clash.razord.top/`: |
| 118 | + - **Chrome**: |
| 119 | + 1. Click the lock icon in the address bar. |
| 120 | + 2. Go to “Site settings” > “Insecure content” > Set to “Allow.” |
| 121 | + - **Firefox**: |
| 122 | + 1. Click the lock icon and go to “Connection settings.” |
| 123 | + 2. Disable “Block dangerous and deceptive content” temporarily. |
| 124 | + - **Warning**: This bypasses security protections and should only be used for local testing on trusted networks. |
| 125 | + - Alternatively, launch Chrome with the `--disable-web-security` flag (for development only): |
| 126 | + ```bash |
| 127 | + google-chrome --disable-web-security --user-data-dir="/tmp/chrome_dev" |
| 128 | + ``` |
| 129 | + |
| 130 | +#### 8. **Check for Conflicting Extensions or Firewall** |
| 131 | + - Browser extensions (e.g., ad blockers, privacy tools) or firewall settings may interfere with Clash’s local server. Temporarily disable extensions or check your firewall to ensure `127.0.0.1:9090` is accessible.[](https://vpncentral.com/reddit-blocked-by-network-security/) |
| 132 | + - On Windows, ensure the Clash app has firewall permissions: |
| 133 | + - Go to Settings > Network & Internet > Windows Firewall > Allow an app through firewall. |
| 134 | + - Add or enable Clash for Windows. |
| 135 | + |
| 136 | +#### 9. **Contact Clash Support or Community** |
| 137 | + - If the above steps don’t resolve the issue, report the problem on the Clash for Windows GitHub issues page (`github.com/Fndroid/clash_for_windows_pkg/issues`) or the Clash community forums. Provide details about your setup, including: |
| 138 | + - Clash version. |
| 139 | + - Operating system. |
| 140 | + - Configuration file (redact sensitive info). |
| 141 | + - Browser and version. |
| 142 | + - Check for similar issues in the community, as this error may be specific to certain Clash versions or configurations.[](https://superuser.com/questions/1769163/could-not-switch-to-this-profile-proxy-0-filed-ws-opts-headershost-invalid-c) |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +### Recommended Approach |
| 147 | +The most secure and robust solution is to **set up a reverse proxy with HTTPS** (step 4) to ensure all requests are served over HTTPS, resolving both the mixed content and CORS issues. If you’re unable to modify the Clash core or dashboard, using a newer version of Clash (e.g., Clash Verge) or accessing the dashboard via HTTP temporarily (step 2) may be quicker workarounds. |
| 148 | + |
| 149 | +--- |
| 150 | + |
| 151 | +### Additional Notes |
| 152 | +- If you’re using a custom Clash dashboard or a third-party service like `clash.razord.top`, verify that it’s compatible with your Clash core version. |
| 153 | +- Always back up your Clash configuration (`config.yaml`) before making changes. |
| 154 | +- If the issue persists, you can try switching to alternative proxy clients like v2rayN or OpenVPN, which may have better HTTPS support for local APIs.[](https://stackoverflow.com/questions/67822697/how-to-route-internet-traffic-via-clash-for-windows-ping-from-python-code-is) |
| 155 | + |
| 156 | +Let me know if you need help with specific steps, such as setting up Nginx or debugging the Clash configuration! |
0 commit comments