You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel队列通过Guzzle发送HTTP请求失败:遇cURL错误56

Hey there, let's tackle this cURL 403 proxy error you're hitting when running Laravel queues via Supervisor—especially since it works fine locally with php artisan queue:work! Here's what's likely going on and how to fix it:

Possible Causes & Solutions

1. Supervisor's Environment Variables Don't Match Your Local Shell

When you run php artisan queue:work locally, your shell loads your user-specific environment variables (like HTTP_PROXY or HTTPS_PROXY). But Supervisor runs processes in a stripped-down environment by default, so it might not inherit these proxy settings, or it's running as a different user (like root) that doesn't have them configured.

Fix:
Add your proxy variables directly to your Supervisor config, or specify the same user you use for local testing:

[program:laravel-queue]
process_name=%(program_name)s_%(process_num)02d
command=php /path/to/your/project/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=your-local-username  # Replace with the user you use for local tests
numprocs=8
redirect_stderr=true
stdout_logfile=/path/to/your/project/storage/logs/queue.log
# Add proxy environment variables here
environment=HTTP_PROXY="http://your-proxy-address:port",HTTPS_PROXY="http://your-proxy-address:port",NO_PROXY="localhost,127.0.0.1"

If your proxy requires authentication, format the URL like this: http://username:password@proxy-address:port

2. Proxy Server Blocks Your Server's IP

Your local development machine's IP is probably whitelisted on the proxy server, but your production server's public IP isn't. The 403 error during the CONNECT step (required for HTTPS requests) is a dead giveaway here—your proxy is refusing to forward traffic from the server's IP.

Fix:
Reach out to your proxy administrator and ask to add your server's public IP to their allowlist for CONNECT requests.

3. Hardcoded Guzzle Proxy Config

If you've hardcoded proxy settings directly in your Guzzle client setup, those might work for your local environment but not for the server (e.g., using an internal proxy that's only accessible from your dev network).

Fix:
Move proxy config to your Laravel .env file so the queue can pick up environment-specific settings:

  1. Add these to .env on your server:
    HTTP_PROXY=http://server-specific-proxy:port
    HTTPS_PROXY=http://server-specific-proxy:port
    
  2. Update your Guzzle client to use these variables:
    $client = new \GuzzleHttp\Client([
        'proxy' => [
            'http' => env('HTTP_PROXY'),
            'https' => env('HTTPS_PROXY'),
        ],
    ]);
    

4. Supervisor Process Permissions

If Supervisor is running the queue as root, it might not have access to the user-specific proxy config stored in files like ~/.bashrc or /etc/profile. These files only load for interactive shell sessions, not for processes started by Supervisor.

Fix:
Confirm the user field in your Supervisor config is set to a non-root user that has the correct proxy environment variables. You can test this by switching to that user on your server and running echo $HTTPS_PROXY to verify the setting exists.

Final Step

After updating your Supervisor config, don't forget to reload and restart the queue:

sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl restart laravel-queue:*

内容的提问来源于stack exchange,提问作者wawanopoulos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:45:11