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

AWS EC2部署MERN电商后无法调用Eazebuzz支付网关问题

电商应用部署AWS EC2后支付网关无法访问问题

我基于MERN栈开发了一个电商应用,后端部署在AWS EC2,前端部署在Vercel。部署后端至AWS EC2后,出现支付网关无法打开的问题,Chrome浏览器网络面板显示504 gateway timeout错误,附带strict-origin-when-cross-origin标识。此前在OnRender平台部署时一切正常。

我已配置AWS安全组的出站规则为HTTP和HTTPS,入站规则包含SSH、HTTPS和HTTP,但仍无法访问支付网关。使用的是Eazebuzz支付网关。


相关路由与代码

本地测试路由

http://localhost:5000/api/schemes/:id/initiate_payment

支付控制器代码

export const initiatePaymentWithEazebuzz = expressAsyncHandler(async (req, res) => {
    const response = await GenSchema.findById({ _id: process.env.GEN_CONFIG_CONFIGURATION_ID });

    const scheme = await Scheme.findOne({ "schemeData._id": req.params.id }, { "schemeData.$": 1, status: 1, user: 1 });

    if (scheme.status !== "active") {
        return res.status(400).json({ error: "This Scheme isn't active anymore. You can't make a payment." });
    }

    const user = await User.findById(scheme.user);

    const amount = scheme.schemeData[0].amount.toFixed(2);
    const phone = user.mobile_number.slice(3);
    const firstname = user.name.split(" ")[0];
    const productinfo = scheme.schemeData[0].month_name;
    const email = user.email;

    const key = response.eazebuzz_merchant_key;
    const salt = response.eazebuzz_salt;
    // const key = process.env.EASEBUZZ_KEY;
    // const salt = process.env.EAZEBUZZ_SALT;
    const txnid = crypto.randomBytes(10).toString("hex");
    const hashSequence = generateHashForEazeBuzz({ key, txnid, amount, productinfo, firstname, email, salt });
    const url = `${process.env.BASE_URL}/payment_result`;

    const formData = {
        key,
        txnid,
        amount,
        email,
        phone,
        firstname,
        hash: hashSequence,
        productinfo,
        furl: url,
        surl: url,
    };

    const eazebuzz_env = process.env.EAZEBUZZ_ENV;
    const geturl = (env) => {
        let url_link;
        if (env === "test") {
            url_link = "https://testpay.easebuzz.in/";
        } else if (env === "prod") {
            url_link = "https://pay.easebuzz.in/";
        } else {
            url_link = "https://testpay.easebuzz.in/";
        }
        return url_link;
    };

    let payment_url = geturl(eazebuzz_env);
    let call_url = payment_url + "payment/initiateLink";

    const options = {
        headers: {
            "Content-Type": "application/x-www-form-urlencoded",
            Accept: "application/json",
        },
    };

    try {
        const { data } = await axios.post(call_url, formData, options);

        if (data.status === 1) {
            await Scheme.findOneAndUpdate(
                { "schemeData._id": req.params.id },
                {
                    $set: {
                        "schemeData.$.txnid": txnid,
                    },
                }
            );
            return res.json({ access_url: data.data, key, env: eazebuzz_env });
        }
    } catch (error) {
        return res.json({ message: error.message });
    }
});

NGINX配置(sites-available文件)

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        listen 443 ssl default_server;
        listen [::]:443 ssl default_server;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name jewellerymine.jewellerskart.in;
        ssl_certificate /etc/nginx/ssl/client-certificate.crt;
        ssl_certificate_key /etc/nginx/ssl/private-ssl.key;

        location /api {
                rewrite ^\/api\/(.*)$ /api/$1 break;
                proxy_pass  http://localhost:5000;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 15:23:15