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

Hostinger Ubuntu VPS爬取政府网站遇Apache/Nginx报错求助

求助:Hostinger Ubuntu VPS无法爬取特定政府网站的问题

我尝试爬取政府网站链接https://ahara.kar.nic.in/status2/时遇到了问题:

  • 在Apache服务器中出现Max retries exceeded with timed out错误
  • 在Nginx服务器中出现upstream prematurely closed connection while reading the response header错误

已经在网上尝试各类解决方案超过一周,仍未解决。

关键现象

  • 相同代码在GoDaddy共享服务器上可正常运行(对应页面:https://mycard.easycardmaker.com/status-page),但在Hostinger的Ubuntu VPS中无法工作
  • 最初采用Flask+Nginx+WSGI部署时出现该问题,以为是Nginx配置问题,重装系统改用Apache服务器后问题依旧
  • 仅在Hostinger Ubuntu VPS访问该政府网站时出现问题,访问其他网站(如https://itunes.apple.com/in/genre/ios-business/id6000?mt=8)无异常

配置参考

部署Ubuntu VPS上的Flask应用时,参考了以下类型的教程:

  1. Flask+Gunicorn+Nginx部署配置教程
  2. Ubuntu VPS上通过Apache部署Flask应用的教程

相关代码及配置

Flask应用代码

from flask import Flask 
import requests
from time import sleep

app = Flask(__name__) 

@app.route("/") 
def hello():
   try:
       headers = {
         "Host": "ahara.kar.nic.in",
         "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
         }
       sleep(5)
       res = requests.get("https://ahara.kar.nic.in/status2/", verify=False, headers=headers, timeout=30)
       print(res.text)
       return "Hello, Got response"
    except requests.ConnectionError as e:
       print(e)
       return 'Failed to establish a connection'

if __name__ == "__main__": 
    app.run()

Apache配置文件 easyCardMakerApp.conf

<VirtualHost *:80>

ServerName 195.35.7.181
ServerAdmin admin@easycardmaker.online
WSGIScriptAlias / /var/www/easyCardMaker/easyCardMaker.wsgi

<Directory /var/www/easyCardMaker>
        Order allow,deny
        Allow from all
        Header set Access-Control-Allow-Origin "*"
</Directory>

Alias /static /var/www/easyCardMaker/static

<Directory /var/www/easyCardMaker/static>
        Order allow,deny
        Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

WSGI文件 easyCardMaker.wsgi

import sys 
import logging 
from app import app as application

logging.basicConfig(stream=sys.stderr) 
sys.path.insert(0,"/var/www/easyCardMaker/")  

application.secret_key = '28fc4673473543eda2e6a9f503f4bb71'

内容的提问来源于stack exchange,提问作者Gopala Raja Naika

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 00:35:36