<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>宝塔面板 Nginx &#8211; 外贸服务器代维护工作室</title>
	<atom:link href="https://www.fuwuqi120.com/tag/%e5%ae%9d%e5%a1%94%e9%9d%a2%e6%9d%bf-nginx/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fuwuqi120.com</link>
	<description>｜外贸网站服务器代维：阿里云 ECS、AWS EC2、Linux、宝塔面板、WordPress 独立站托管与排障。</description>
	<lastBuildDate>Tue, 17 Nov 2026 18:17:41 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Nginx 常见错误排查指南：外贸站实战</title>
		<link>https://www.fuwuqi120.com/nginx-%e5%b8%b8%e8%a7%81%e9%94%99%e8%af%af%e6%8e%92%e6%9f%a5%e6%8c%87%e5%8d%97%ef%bc%9a%e5%a4%96%e8%b4%b8%e7%ab%99%e5%ae%9e%e6%88%98/</link>
					<comments>https://www.fuwuqi120.com/nginx-%e5%b8%b8%e8%a7%81%e9%94%99%e8%af%af%e6%8e%92%e6%9f%a5%e6%8c%87%e5%8d%97%ef%bc%9a%e5%a4%96%e8%b4%b8%e7%ab%99%e5%ae%9e%e6%88%98/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 17 Nov 2026 18:17:41 +0000</pubDate>
				<category><![CDATA[linux服务器代维]]></category>
		<category><![CDATA[AWS EC2 网站打不开]]></category>
		<category><![CDATA[Nginx 常见错误排查指南]]></category>
		<category><![CDATA[WordPress 海外访问慢]]></category>
		<category><![CDATA[外贸独立站 502]]></category>
		<category><![CDATA[宝塔面板 Nginx]]></category>
		<guid isPermaLink="false">https://www.fuwuqi120.com/nginx-%e5%b8%b8%e8%a7%81%e9%94%99%e8%af%af%e6%8e%92%e6%9f%a5%e6%8c%87%e5%8d%97%ef%bc%9a%e5%a4%96%e8%b4%b8%e7%ab%99%e5%ae%9e%e6%88%98/</guid>

					<description><![CDATA[先看 30 秒状态码和 error_log，再分两节处理 502/504、403/404 与 SSL；命令按机器和身份给全，照着跑就能定位海外客户打不开的原因。]]></description>
										<content:encoded><![CDATA[<div class="fuwuqi120-answer">
<p><strong>一句话答案：</strong>先看 30 秒状态码和 error_log，再分两节处理 502/504、403/404 与 SSL；命令按机器和身份给全，照着跑就能定位海外客户打不开的原因。</p>
</div>
<div class="fuwuqi120-toc">
<p><strong>本文目录</strong></p>
<ol>
<li><a href="#fuwuqi120-h2-1">先给结论：30 秒判断是哪一层坏了</a></li>
<li><a href="#fuwuqi120-h2-2">现象与原因：502、504、403、404 分别对应什么</a></li>
<li><a href="#fuwuqi120-h2-3">解决步骤一：后端不通、超时、权限（在 Web 机器改）</a></li>
<li><a href="#fuwuqi120-h2-4">解决步骤二：伪静态、端口放行、跨洋线路（分机器执行）</a></li>
<li><a href="#fuwuqi120-h2-5">怎么验证修好：别只看自己电脑能打开</a></li>
<li><a href="#fuwuqi120-h2-6">怎么避免再犯：迁移和改配置前留退路</a></li>
</ol>
</div>
<h2 id="fuwuqi120-h2-1">先给结论：30 秒判断是哪一层坏了</h2>
<p><strong>先跑一次 curl 看状态码和耗时，再登机器看 error_log，别动重启。</strong>这一步 30 秒能分清是线路、后端还是防火墙坏了。</p>
<p>外贸站报障，我最怕对方上来就 <code>systemctl restart nginx</code>。接手过的阿里云 ECS、AWS EC2 单子里，八成问题出在 <a href="https://www.fuwuqi120.com/tag/php-fpm/">PHP-FPM</a> 挂了、上游 9000 端口没监听、或者证书链少了一级 intermediate，Nginx 进程本身好得很。重启会把现场冲掉，<code>error.log</code> 里那几行 <code>connect() failed (111: Connection refused)</code> 一滚就没了，后面只能靠猜。WordPress 独立站尤其常见，客户那边刚推了一版插件，FPM 子进程被打满，页面直接 502，重启 Nginx 一点用没有。</p>
<p>在<strong>办公电脑</strong>，普通用户身份，不用登服务器，先跑这条：</p>
<pre><code>curl -I -o /dev/null -w '%{http_code} %{time_total} %{remote_ip}n' --connect-timeout 5 https://www.example.com
</code></pre>
<p>把 <code>www.example.com</code> 换成客户真实域名。判法很直白：</p>
<ul>
<li><strong>200 且 time_total &gt; 3s</strong>：多半是线路，不是配置。页面能开，欧美客户嫌慢。</li>
<li><strong>502 / 504</strong>：看后端。502 查 PHP-FPM 或 upstream 端口，504 查 <code>fastcgi_read_timeout</code> 和数据库慢查询。</li>
<li><strong>000</strong>：连都没连上。查安全组、<code>iptables</code>、AWS Security Group 的 443 入站，或者域名解析到了旧 ECS 的 IP。</li>
</ul>
<p>同一条命令，我会让客户找新加坡和法兰克福各跑一次，自己这边留一份对照。见过一组数：法兰克福 1.2s、新加坡 4.3s、深圳办公网 0.9s。这种差值基本就是单台 ECS 只挂了国内 BGP，没走海外节点，东南亚客户绕了一圈才落地。换 CN2 GIA 或加一层海外边缘节点能压到 2s 内，月成本大概多 150 到 400 元，具体看流量，我不敢报死数。也见过反过来，欧美慢、东南亚快，那是源站放在新加坡但没配欧美回源加速，跟 Nginx 无关。</p>
<p>确认不是纯线路问题，再<strong>登录目标服务器</strong>，root 或带 sudo 的账号，宝塔面板机器也一样走 SSH，别只在面板里点「重载配置」：</p>
<pre><code>sudo nginx -t &amp;&amp; sudo systemctl is-active nginx &amp;&amp; sudo tail -n 30 /var/log/nginx/error.log
</code></pre>
<p>Nginx 1.20 到 1.26 这几个版本路径都一样，Ubuntu 22.04 和 Alibaba Cloud Linux 3 都适用；宝塔装的一般在 <code>/www/server/nginx/logs/error.log</code>，上面那条读不到就换这个路径。<code>nginx -t</code> 出 <code>syntax is ok</code> 只说明配置文件没写错，不代表上游活着，这个坑我早期踩过。报错原文先整段复制存到工单里，别边看边改。尤其带 <code>SSL: error:0A000086</code> 或 <code>upstream timed out</code> 的行，后面配证书链、调 <code>fastcgi_read_timeout 120s</code> 都要拿它比对。存档完再往下走 502/504 那一层。</p>
<h2 id="fuwuqi120-h2-2">现象与原因：502、504、403、404 分别对应什么</h2>
<p>502 是后端没接上，504 是后端太慢，403 看权限，404 看伪静态，SSL 另算。</p>
<p>这四个码别混着查。我接外贸站宕机单，一半时间不是 Nginx 挂了，是后面 PHP、回调、文件属主或者一条 rewrite 没带过来。按码分，比翻整份配置快得多。</p>
<table>
<tr>
<th>状态码</th>
<th>error_log 里的原话</th>
<th>外贸站最常见触发点</th>
</tr>
<tr>
<td><strong>502</strong></td>
<td>connect() failed (111: Connection refused) while connecting to upstream</td>
<td>宝塔切 PHP 版本后 9000 没监听</td>
</tr>
<tr>
<td><strong>504</strong></td>
<td>upstream timed out (110: Connection timed out) while reading response header</td>
<td>WooCommerce 结账页等 PayPal / Stripe 跨洋回调</td>
</tr>
<tr>
<td><strong>403</strong></td>
<td>directory index of &#8220;/home/wwwroot/xxx/&#8221; is forbidden</td>
<td>迁移后属主变 root，worker 是 www</td>
</tr>
<tr>
<td><strong>404</strong></td>
<td>日志通常不报错，只有 access 里一条 404</td>
<td>漏了 try_files，/us/ 落地页全丢</td>
</tr>
</table>
<p>502 我踩过好几次。宝塔面板把 PHP 从 7.4 改到 8.1，站点看着正常，php-fpm 实际没拉起，Nginx 往 127.0.0.1:9000 一撞就是 111。欧美客户那边直接白屏，国内测有时候还缓存着旧页面，容易误判成 CDN 问题。在<strong>应用服务器 ECS、root 身份</strong>跑：</p>
<pre><code>ss -lntp | grep ':9000'
systemctl status php-fpm-81 | head -20
tail -n 30 /www/server/nginx/logs/xxx.com.error.log
grep -n 'fastcgi_pass' /www/server/panel/vhost/nginx/xxx.com.conf</code></pre>
<p>端口空着就起服务，别先动 Nginx。<code>systemctl restart php-fpm-81</code> 完事，30 秒内再刷一次结账页。</p>
<p>504 不一样，后端活着，只是没在 60 秒内回 header。<code>fastcgi_read_timeout</code> 默认 60s，Stripe 从美国东岸回传到新加坡 EC2，碰上 3D Secure 验证经常跑到 70~90 秒。我一般给 WooCommerce 站点单独加到 120s，不整站放宽，免得慢请求把 php-fpm 子进程占满。改完 <code>nginx -t &amp;&amp; nginx -s reload</code>，别 restart。</p>
<p>403 先看属主。迁移站用 root 解压 tar 包，<code>/home/wwwroot/xxx/</code> 全变 root:root，Nginx worker 跑的是 www，静态图、webp、Google 抓取一起掉。日志那句 <em>directory index &#8230; is forbidden</em> 已经把路径写死了。修法就一条，别顺手 chmod 777：</p>
<pre><code>chown -R www:www /home/wwwroot/xxx/
find /home/wwwroot/xxx/ -type d -exec chmod 755 {} ;
find /home/wwwroot/xxx/ -type f -exec chmod 644 {} ;
ps -eo user,comm | grep 'nginx' | head -5</code></pre>
<p>404 但 FTP 里文件明明在，九成是 WordPress 迁移漏了伪静态。尤其投欧美广告的 /us/、/uk/ 落地页，带子路径时没有 <code>try_files $uri $uri/ /index.php?$args;</code>，Nginx 直接当物理目录找，找不到就 404。宝塔里别选「纯静态」，选 wordpress 规则再重载。</p>
<p>最后单说 SSL。<code>NET::ERR_CERT_DATE_INVALID</code>、<code>no start line</code> 和上面四个码不是一层，浏览器在 TLS 握手就断了，Nginx access 日志里连请求都没有。海外 Chrome / Safari 对链不完整比国内敏感得多，Let’s Encrypt 只塞了 cert.pem、没带 fullchain.pem，国内某些网络能过，德国和巴西客户基本全红。证书路径指 fullchain.pem，<code>openssl x509 -in fullchain.pem -noout -dates</code> 先核有效期，再 <code>nginx -t</code>。这块不归状态码管，别在 502 里翻它。</p>
<h2 id="fuwuqi120-h2-3">解决步骤一：后端不通、超时、权限（在 Web 机器改）</h2>
<p>先查监听和 PHP-FPM，再改超时、权限、证书链，都在 Web 机做。</p>
<p>这一步别碰 Nginx 主配置。我处理<a href="https://www.fuwuqi120.com/tag/%e5%a4%96%e8%b4%b8%e7%8b%ac%e7%ab%8b%e7%ab%99/">外贸独立站</a> 502，十次里有七次是后端没起来，或者 PHP 版本被面板切过。欧美客户正在结账时，乱 restart 比报错更麻烦。下面命令都在<strong>阿里云 ECS / AWS EC2 那台 Web 节点</strong>执行，身份 <strong>root 或 sudo</strong>。30 秒先看端口：</p>
<pre><code>ss -lntp | grep -E ':(80|443|9000|9001)'
php -v</code></pre>
<p>没看到 9000 或 9001，就停手。别去改 fastcgi_pass，改了也是空转。宝塔环境常见进程在 <strong>/www/server/php/74/sbin/php-fpm</strong>，对应服务名 php-fpm-74；Ubuntu 22.04 自带一般是 <strong>php8.1-fpm</strong>。版本不确定就以上面 php -v 为准，我见过一台新加坡节点被装了 7.4 和 8.1 两套，站点配置指 7.4，开机自启的却是 8.1，东南亚客户白天打不开，半夜又自己好了。</p>
<pre><code>systemctl restart php-fpm-74 &amp;&amp; systemctl enable php-fpm-74
systemctl restart php8.1-fpm &amp;&amp; systemctl enable php8.1-fpm
ss -lntp | grep -E ':(9000|9001)'</code></pre>
<p>两条按实际版本选一条跑，别都跑。端口回来之后，再处理 504。跨境到欧美走普通 BGP，WordPress 后台跑汇率插件或同步支付回调，经常卡到 60 秒以上。参数放进 <strong>server 块或 location ~ .php$</strong>，不要塞 http 全局，免得把静态资源也拖住：</p>
<pre><code>fastcgi_read_timeout 120s;
fastcgi_connect_timeout 30s;
fastcgi_send_timeout 120s;</code></pre>
<p>改完用 reload，不用 restart。正在提交 Stripe / PayPal 订单的连接不会被掐断，这个坑我踩过一次，客户重复扣款，查了两天日志。</p>
<pre><code>nginx -t &amp;&amp; systemctl reload nginx</code></pre>
<p>403 多半是迁移后属主变了。从旧 ECS  rsync 过来，文件带的是 root，Nginx worker 跑 www，读不了 wp-content。一条收口，路径按站点根目录换：</p>
<pre><code>chown -R www:www /home/wwwroot/example.com &amp;&amp; find /home/wwwroot/example.com -type d -exec chmod 755 {} ; &amp;&amp; find /home/wwwroot/example.com -type f -exec chmod 644 {} ;
chmod 600 /home/wwwroot/example.com/wp-config.php</code></pre>
<p>wp-config.php 里有数据库和支付密钥，单独回 600。别整站 777，海外扫描器扫到就是后门。</p>
<p>证书补链放最后。只配 cert.pem 不带中间链，Chrome 在欧美能过，部分东南亚安卓机和旧版 Safari 会直接报不安全，看着像「客户打不开」。改成 fullchain：</p>
<pre><code>ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;</code></pre>
<pre><code>nginx -t &amp;&amp; systemctl reload nginx
curl -I -m 10 https://example.com/</code></pre>
<p>curl 那行只测本机出站。真要确认海外线路，还得从目标区域再打一次，本机 200 不代表洛杉矶能开。证书续期后没 reload 也会出现这类偏差，我一般把 reload 挂进续期钩子，不靠人记。</p>
<h2 id="fuwuqi120-h2-4">解决步骤二：伪静态、端口放行、跨洋线路（分机器执行）</h2>
<p>伪静态、安全组、线路要分三台地方改，只动 Nginx 不够。</p>
<p>上一节把后端和权限处理完，还剩一类最容易被漏掉的：页面能开，但点产品详情 404；控制台端口全绿，欧美客户照样打不开；ALB 后面机器一直 unhealthy。我接外贸站迁移单，十次里有三四次卡在这层，跟 PHP 没关系。</p>
<p>30 秒先判一下。在<strong>Web 机器、root</strong> 上跑下面两条，看是不是规则没写进去、端口是不是真在听：</p>
<pre><code>nginx -T 2&gt;/dev/null | grep -n "try_files" | head -5
ss -lntp | grep -E ':80|:443'
firewall-cmd --list-ports</code></pre>
<p>第一条没输出，就是 WordPress 伪静态丢了。固定链接一改，<code>/product/valve-304/</code> 直接 404，Google 收录的落地页也跟着废。写进 <code>/etc/nginx/conf.d/example.com.conf</code> 的 <code>server {}</code> 块里，别丢进宝塔面板生成的那份 vhost，我见过两边互相覆盖，reload 完又回退。</p>
<pre><code>cat &gt; /etc/nginx/conf.d/example.com.conf &lt;&lt;'EOF'
server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ .php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
EOF

nginx -t &amp;&amp; systemctl reload nginx</code></pre>
<p>端口得两头看。阿里云 ECS 控制台安全组入方向放 <strong>TCP 80/443，源 0.0.0.0/0</strong>；AWS EC2 是 Security Group Inbound 加 <strong>HTTPS TCP 443, 0.0.0.0/0</strong>。机器内 firewalld 是另一层，<code>firewall-cmd --list-ports</code> 空着就补 <code>firewall-cmd --permanent --add-service=http --add-service=https &amp;&amp; firewall-cmd --reload</code>。只改控制台不改机器内，这个坑我踩过，新加坡节点晾了半天。</p>
<table>
<tr>
<th>位置</th>
<th>要改的项</th>
<th>漏了的表现</th>
</tr>
<tr>
<td>阿里云 ECS 安全组</td>
<td>入方向 80/443，0.0.0.0/0</td>
<td>国内通、海外超时</td>
</tr>
<tr>
<td>AWS Security Group</td>
<td>Inbound HTTPS TCP 443</td>
<td>浏览器直接 connection refused</td>
</tr>
<tr>
<td>ALB Target Group</td>
<td>Health check path <code>/</code>，端口 80 或 traffic-port</td>
<td>一直 unhealthy，客户看到 502</td>
</tr>
</table>
<p>AWS 那个健康检查最阴。EC2 只开 443，检查却设成 80，Nginx 日志干干净净，ALB 就是不转发，欧美客户吃 502。控制台里把 path 改成 <code>/</code>、端口选 <code>traffic-port</code>，30 秒左右状态会转 healthy。支付回调走这条路的话，别拖到结账时段再改。</p>
<p>跨洋慢不是 Nginx 报错，<code>error_log</code> 里翻不到东西。单台 2核4G ECS 月费大致 60-120 元，加一台海外轻量节点做反代或挂 CDN，预算通常 150-400 元/月。欧美还是东南亚线路，按客户分布实测，我不替你拍板；我一般先拿两地各跑 3 天 MTR 再定节点。</p>
<p>上了反代机，<strong>反代机、root</strong> 必须透传真实 IP，不然 WordPress 评论、风控和支付回调全记成 172.16 段内网地址，后面查拒付没法对账：</p>
<pre><code>cat &gt; /etc/nginx/conf.d/proxy.conf &lt;&lt;'EOF'
server {
    listen 80;
    server_name example.com www.example.com;

    location / {
        proxy_pass http://10.0.2.15:80;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_connect_timeout 10s;
        proxy_read_timeout 60s;
    }
}
EOF

nginx -t &amp;&amp; systemctl reload nginx</code></pre>
<p><code>10.0.2.15</code> 换成实际 Web 机器内网 IP，别填公网，跨一次公网绕回来源站反而更慢。改完从欧美节点 curl 一次带 <code>-H "X-Forwarded-For: 203.0.113.9"</code>，去 WordPress 后台看评论 IP 对不对，对了再放流量。</p>
<h2 id="fuwuqi120-h2-5">怎么验证修好：别只看自己电脑能打开</h2>
<p>修没修好要从海外侧、结账链路和证书链各验一遍，本机 200 不算完。</p>
<p>我见过太多次这种收尾：运维在自己电脑上刷新一下首页，200，就回老板「好了」。第二天德国客户发邮件说结账页转圈，美国那边 PayPal 回调 504，单子丢在半路。跨境链路里，首页往往命中了 CDN 缓存，真正走 PHP-FPM、查库、连支付网关的路径根本没被碰到。自己电脑能开，只证明你这条网到这台机器通。</p>
<p>先在 Web 机器上用 root 或 sudo 身份复跑三次。别只跑一次，Nginx reload 后头一两秒偶尔还会撞上旧 worker。</p>
<pre><code># 在 Web 机器（阿里云 ECS / AWS EC2）执行，身份：root 或具有 sudo 权限的运维账号
for i in 1 2 3; do curl -I -o /dev/null -w '%{http_code} %{time_total}n' --connect-timeout 5 https://www.example.com; done
curl -I --connect-timeout 5 https://www.example.com/checkout/
curl -I --connect-timeout 5 'https://www.example.com/wc-api/WC_Gateway_Paypal/?order_id=8891&amp;key=wc_order_5f2a7c'
openssl s_client -connect www.example.com:443 -servername www.example.com -showcerts /dev/null | grep -c 'BEGIN CERTIFICATE'</code></pre>
<p>三次都得是 <strong>200</strong>，time_total 波动小于 <strong>0.5s</strong> 才算稳。checkout 和带回调参数的 /wc-api/ 路径单独看，504 最容易藏在这里，首页 200 不代表收款能用。证书那条返回 <strong>2 以上</strong>基本正常，只回 1 说明中间链没配全，部分东南亚安卓机就会直接报不安全，欧美 Chrome 反倒不一定复现。</p>
<p>海外侧我一般用两台不同区域的小机器各跑一次 curl，比如一台法兰克福、一台新加坡，1 核 1G 规格就够，月成本大概 3–8 美元区间；临时借免费探测点也行。两边数字差个 200–400ms 很正常，跨洋线路本来就不平。误差摆在那，别拿单次数字跟老板报 SLA，我吃过这个亏。</p>
<p>最后挂日志收尾，边看边真下一笔测试单，别用缓存页糊弄。</p>
<pre><code># 在 Web 机器执行，身份：root；保持窗口 5 分钟，同时在浏览器完成一次下单+回调
tail -f /var/log/nginx/error.log
# 另开一个窗口，按时间窗口过滤刚才这 5 分钟
grep -E 'upstream timed out|Connection refused' /var/log/nginx/error.log | tail -n 50</code></pre>
<p>5 分钟内没有新的 <strong>upstream timed out</strong> 或 <strong>Connection refused</strong>，支付回调也落库了，工单就可以关。要是只冒出一条 404 且路径是 /favicon.ico，不用管。宝塔面板环境日志可能在 /www/wwwlogs/ 下，路径对不上先 <code>nginx -T 2&gt;/dev/null | grep error_log</code> 确认一遍，别盯错文件白等五分钟。</p>
<h2 id="fuwuqi120-h2-6">怎么避免再犯：迁移和改配置前留退路</h2>
<p>改配置前留一份可回滚的副本，比出事后翻聊天记录找原配置省事得多。</p>
<p>我接外贸站搬迁单，返工里一半以上不是备案、不是支付接口，就是 PHP 版本、fastcgi_pass 地址、证书路径这三项对不上。比如旧机是 PHP 8.1 走 127.0.0.1:9000，新机装了 PHP 8.2 默认走 /run/php/php8.2-fpm.sock，conf 原样拷过去，欧美客户先看到 502，自己本地测还不一定复现。迁移清单我一般就写死这三项，加一列「旧机实际值 / 新机实际值」，不写「同旧环境」这种话。</p>
<p>在 Web 机器、root 身份执行，动手前先备份：</p>
<pre><code>cp /etc/nginx/conf.d/example.com.conf /etc/nginx/conf.d/example.com.conf.$(date +%F-%H%M).bak
nginx -t
systemctl reload nginx
ls -l /etc/nginx/conf.d/example.com.conf.*.bak | tail -n 5
</code></pre>
<p>宝塔面板有个坑我踩过好几次。你在站点伪静态框里手写的 rewrite，点一次「保存」或者切换 PHP 版本，它按模板重生成一遍 vhost，手写规则就没了。改完必须回看一次 /www/server/panel/vhost/nginx/example.com.conf，别只看面板上显示「已保存」。跨洋线路调优塞在 location 里的 header、proxy_read_timeout 也照样会被盖掉。</p>
<p>证书别靠人记。Let’s Encrypt 90 天，提前 30 天续，root 加一条 crontab 就够，reload 而不是 restart，避免半夜把正在结账的会话踹断：</p>
<pre><code>echo "0 3 * * * certbot renew --quiet --deploy-hook 'systemctl reload nginx'" &gt;&gt; /var/spool/cron/crontabs/root
crontab -l | grep certbot
certbot renew --dry-run
</code></pre>
<p>监控我只盯三个数：<strong>5xx 比例</strong>、<strong>upstream_response_time</strong>、<strong>443 握手失败</strong>。2核4G 的 ECS 跑外贸站够用，但 /var/log/nginx/*.log 攒两个月很容易把 40G 系统盘写满，盘一满 Nginx 直接返 500，东南亚客户先投诉。按天切、留 14 天：</p>
<pre><code>cat &gt; /etc/logrotate.d/nginx-foreign &lt;&lt;'EOF'
/var/log/nginx/*.log {
    daily
    rotate 14
    compress
    missingok
    notifempty
    sharedscripts
    postrotate
        [ -f /var/run/nginx.pid ] &amp;&amp; kill -USR1 $(cat /var/run/nginx.pid)
    endscript
}
EOF
logrotate -d /etc/logrotate.d/nginx-foreign
df -h /
</code></pre>
<p>代维包年我见过的区间是 3000-12000 元/年，差的不在「安全加固」四个字，在含不含迁移、半夜宕机有没有人接。合同里写清响应时限（我一般要求 30 分钟内回、2 小时内给临时回滚）和备份保留天数（至少 7 天，跨大促按 14 天），比堆功能描述管用。不确定对方能不能做到海外时段值守，就先问一次「美东晚上 21:00 打不开，谁接电话」，答不上来的别签。</p>
<h2 id="fuwuqi120-faq">常见问题</h2>
<h3>外贸网站首页 200 但结账页 504 Gateway Time-out 怎么查</h3>
<p>多半是支付回调跨洋超时。把 fastcgi_read_timeout 提到 120s，reload 后单独 curl /checkout/ 验证。</p>
<h3>宝塔面板升级 PHP 后整站 502 Connection refused 怎么办</h3>
<p>9000 端口没起来。ss -lntp 看监听，重启对应 php-fpm-74 或 php8.1-fpm，再 nginx -t。</p>
<h3>阿里云 ECS 安全组放了 443 海外客户还是打不开</h3>
<p>查机器内 firewalld 和 ALB/ECS 监听是否一致。firewall-cmd &#8211;list-ports，控制台和本机两处都要放。</p>
<h3>WordPress 迁移到 AWS EC2 后 /us/ 落地页全 404</h3>
<p>漏了伪静态。server 块补 try_files $uri $uri/ /index.php?$args; ，nginx -t 后 reload。</p>
<h3>Nginx 换了 Let’s Encrypt 证书欧美浏览器仍报不安全</h3>
<p>多半只用了 cert.pem。改成 fullchain.pem，openssl s_client 数证书链，返回 2 以上再测。</p>
<div class="fuwuqi120-cta">
<p>服务器又出问题了？外贸站的宕机、被黑、迁移和访问慢，我们按次或按月代维，先免费看机器再报价。</p>
<p><a class="fuwuqi120-cta-btn" href="/service/">看看代维服务</a></p>
</div>
<div class="fuwuqi120-grid">
<p class="fuwuqi120-grid-title"><strong>0</strong></p>
<div class="fuwuqi120-grid-inner"><a class="fuwuqi120-card" href="https://www.fuwuqi120.com/nginx-%e7%bd%91%e5%85%b3%e9%94%99%e8%af%af%e6%8e%92%e6%9f%a5%ef%bc%9a%e5%a4%96%e8%b4%b8%e7%ab%99-502-504-%e5%ae%9e%e5%bd%95/"><span class="fuwuqi120-card-thumb" style="background-image:url(https://www.fuwuqi120.com/wp-content/uploads/2026/11/nginx-e7bd91e585b3e99499e8afafe68e92e69fa5efbc9ae5a496e8b4b8e7ab99-502-504-e5ae9ee5bd95-zZIlPd-768x430.webp)" aria-hidden="true"></span><span class="fuwuqi120-card-body"><span class="fuwuqi120-card-cat">linux服务器代维</span><span class="fuwuqi120-card-title">Nginx 网关错误排查：外贸站 502/504 实录</span><span class="fuwuqi120-card-date">2026-11-18</span></span></a><a class="fuwuqi120-card" href="https://www.fuwuqi120.com/%e5%a4%96%e8%b4%b8%e7%ab%99%e5%ae%9d%e5%a1%94%e9%9d%a2%e6%9d%bf%e5%ae%89%e8%a3%85%e5%91%bd%e4%bb%a4%ef%bc%9a%e5%85%88%e9%80%89%e7%b3%bb%e7%bb%9f%e5%86%8d%e8%a3%85/"><span class="fuwuqi120-card-thumb" style="background-image:url(https://www.fuwuqi120.com/wp-content/uploads/2026/11/e5a496e8b4b8e7ab99e5ae9de5a194e99da2e69dbfe5ae89e8a385e591bde4bba4efbc9ae58588e98089e7b3bbe7bb9fe5868de8a385-vU0FgY-768x430.webp)" aria-hidden="true"></span><span class="fuwuqi120-card-body"><span class="fuwuqi120-card-cat">linux服务器代维</span><span class="fuwuqi120-card-title">外贸站宝塔面板安装命令：先选系统再装</span><span class="fuwuqi120-card-date">2026-11-15</span></span></a><a class="fuwuqi120-card" href="https://www.fuwuqi120.com/wordpress-%e5%a4%96%e8%b4%b8%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%85%a8%e9%9d%a2%e7%bb%b4%e6%8a%a4%e6%9c%8d%e5%8a%a1%ef%bc%88%e6%94%af%e6%8c%81%e4%b8%ad%e8%8b%b1%e6%96%87%ef%bc%89/"><span class="fuwuqi120-card-thumb" style="background-image:url(https://www.fuwuqi120.com/wp-content/uploads/2026/11/wordpress-e5a496e8b4b8e69c8de58aa1e599a8e585a8e99da2e7bbb4e68aa4e69c8de58aa1efbc88e694afe68c81e4b8ade88bb1e69687efbc89-L09wI0-768x430.webp)" aria-hidden="true"></span><span class="fuwuqi120-card-body"><span class="fuwuqi120-card-cat">aliyun服务器代维</span><span class="fuwuqi120-card-title">WordPress 外贸服务器全面维护服务（支持中英文）</span><span class="fuwuqi120-card-date">2020-02-28</span></span></a><a class="fuwuqi120-card" href="https://www.fuwuqi120.com/%e4%bc%81%e4%b8%9a%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%89%98%e7%ae%a1%e8%bf%90%e7%bb%b4/"><span class="fuwuqi120-card-thumb" style="background-image:url(https://www.fuwuqi120.com/wp-content/uploads/2026/11/e4bc81e4b89ae69c8de58aa1e599a8e68998e7aea1e8bf90e7bbb4-E1vdzG-768x430.webp)" aria-hidden="true"></span><span class="fuwuqi120-card-body"><span class="fuwuqi120-card-cat">linux代维</span><span class="fuwuqi120-card-title">企业服务器托管运维</span><span class="fuwuqi120-card-date">2020-02-28</span></span></a><a class="fuwuqi120-card" href="https://www.fuwuqi120.com/%e5%a4%96%e8%b4%b8%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%bb%a3%e7%bb%b4%e6%8a%a4/"><span class="fuwuqi120-card-thumb" style="background-image:url(https://www.fuwuqi120.com/wp-content/uploads/2026/11/e5a496e8b4b8e69c8de58aa1e599a8e4bba3e7bbb4e68aa4-pA6qcr-768x430.webp)" aria-hidden="true"></span><span class="fuwuqi120-card-body"><span class="fuwuqi120-card-cat">linux服务器代维</span><span class="fuwuqi120-card-title">外贸服务器代维护</span><span class="fuwuqi120-card-date">2020-02-28</span></span></a><a class="fuwuqi120-card" href="https://www.fuwuqi120.com/%e7%bd%91%e7%ab%99%e6%90%ac%e5%ae%b6%e6%95%b0%e6%8d%ae%e8%bf%81%e7%a7%bb-%e7%bd%91%e7%ab%99%e6%90%ac%e5%ae%b6-%e6%95%b0%e6%8d%ae%e5%ba%93%e8%bf%81%e7%a7%bb/"><span class="fuwuqi120-card-thumb" style="background-image:url(https://www.fuwuqi120.com/wp-content/uploads/2026/11/e7bd91e7ab99e690ace5aeb6e695b0e68daee8bf81e7a7bb-e7bd91e7ab99e690ace5aeb6-e695b0e68daee5ba93e8bf81e7a7bb-e5afbce585a5e5afbce587ba-T8N1S9-768x430.webp)" aria-hidden="true"></span><span class="fuwuqi120-card-body"><span class="fuwuqi120-card-cat">linux代维</span><span class="fuwuqi120-card-title">网站搬家数据迁移 网站搬家 数据库迁移 导入导出</span><span class="fuwuqi120-card-date">2020-02-17</span></span></a><a class="fuwuqi120-card" href="https://www.fuwuqi120.com/%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%bb%a3%e8%bf%90%e7%bb%b4_%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%89%98%e7%ae%a1_%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%bb%b4%e6%8a%a4-2/"><span class="fuwuqi120-card-thumb" style="background-image:url(https://www.fuwuqi120.com/wp-content/uploads/2026/11/e69c8de58aa1e599a8e4bba3e8bf90e7bbb4_e69c8de58aa1e599a8e68998e7aea1_e69c8de58aa1e599a8e7bbb4e68aa4-5d7ISz-768x430.webp)" aria-hidden="true"></span><span class="fuwuqi120-card-body"><span class="fuwuqi120-card-cat">linux服务器代维</span><span class="fuwuqi120-card-title">服务器代运维_服务器托管_服务器维护</span><span class="fuwuqi120-card-date">2020-02-13</span></span></a><a class="fuwuqi120-card" href="https://www.fuwuqi120.com/%e7%bd%91%e7%ab%99%e5%9f%ba%e7%a1%80%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba/"><span class="fuwuqi120-card-thumb" style="background-image:url(https://www.fuwuqi120.com/wp-content/uploads/2026/11/e7bd91e7ab99e59fbae7a180e78eafe5a283e690ade5bbba-7UVOU2-768x430.webp)" aria-hidden="true"></span><span class="fuwuqi120-card-body"><span class="fuwuqi120-card-cat">linux服务器代维</span><span class="fuwuqi120-card-title">网站基础环境搭建</span><span class="fuwuqi120-card-date">2019-03-05</span></span></a><a class="fuwuqi120-card" href="https://www.fuwuqi120.com/%e4%b8%8a%e4%ba%91%e5%92%a8%e8%af%a2-%e4%b8%8a%e4%ba%91%e8%bf%81%e7%a7%bb%ef%bc%88%e4%bc%81%e4%b8%9a%e9%a6%96%e6%ac%a1%e4%b8%8a%e4%ba%91%e6%9c%8d%e5%8a%a1%ef%bc%89/"><span class="fuwuqi120-card-thumb" style="background-image:url(https://www.fuwuqi120.com/wp-content/uploads/2026/11/e4b88ae4ba91e592a8e8afa2-e4b88ae4ba91e8bf81e7a7bbefbc88e4bc81e4b89ae9a696e6aca1e4b88ae4ba91e69c8de58aa1efbc89-LFeoMR-768x430.webp)" aria-hidden="true"></span><span class="fuwuqi120-card-body"><span class="fuwuqi120-card-cat">aliyun服务器代维</span><span class="fuwuqi120-card-title">上云咨询 上云迁移（企业首次上云服务）</span><span class="fuwuqi120-card-date">2019-03-05</span></span></a></div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.fuwuqi120.com/nginx-%e5%b8%b8%e8%a7%81%e9%94%99%e8%af%af%e6%8e%92%e6%9f%a5%e6%8c%87%e5%8d%97%ef%bc%9a%e5%a4%96%e8%b4%b8%e7%ab%99%e5%ae%9e%e6%88%98/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
