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

Java 18+NLTK的Flask脚本经Nginx运行时返回500错误求助

Flask API调用Stanford NERTagger时systemctl服务返回500错误

我有一个基于Flask的Python API脚本,用于读取文本并识别其中的人名,功能依赖NLTK库及Stanford NER实现。服务器已安装Java 18,直接运行python3 testFile.py时功能完全正常,但通过systemctl管理的服务经Nginx调用时,该API返回500内部服务器错误。

其余API在Nginx环境下均可正常运行,且移除该API中的NLTK相关逻辑后,也能正常工作。已检查Nginx错误日志,但未记录此500错误的相关信息。

相关代码与配置

testFile.py

import nltk
from nltk import tag

st = tag.stanford.StanfordNERTagger('stanford-ner/classifiers/english.all.3class.distsim.crf.ser.gz',
                                    'stanford-ner/stanford-ner.jar')

def isValidAddress(text):
    # nltk.download('punkt')

    tokens = nltk.word_tokenize(text)
    tags = st.tag(tokens)

    for item in tags:
        if item[1] == "PERSON":
            return True

    return False

Nginx配置文件(/etc/nginx/sites-available/default)

server {
        listen 80;
        listen [::]:80;
        location / {
            proxy_pass http://127.0.0.1:5000;
            proxy_set_header X-Real-IP $remote_addr;
        }
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    include snippets/self-signed.conf;
    include snippets/ssl-params.conf;
 location / {
            proxy_pass https://127.0.0.1:5000;
            proxy_set_header X-Real-IP $remote_addr;
        }
}

systemctl服务配置

[Unit]
Description=Autoscale Flask project
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/root/smartcap-ai
ExecStart=/usr/bin/python3.6 /root/smartcap-ai/main.py
[Install]
WantedBy=multi-user.target

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 13:35:46