flask url_for后没有带端口号

问题描述:

在本地运行flask项目,当运行到下面这句代码时,正常重定向

        return redirect(url_for('.script_case'))

但项目布署到服务器之后,代码运行一这句话,却报了404 Not Found

问题分析:

  仔细看了url是没有端口号.

  正确的地址:

http://10.2.1.92:8001/script_case

  实际请求的地址:

10.2.1.92/script_case

解决步骤 :

  查找nginx配置文件

[root@67 ~]# find  / -name nginx.conf
/etc/nginx/nginx.conf

  编辑nginx配置文件

nano /etc/nginx/nginx.conf

  指定nginx运行的端口号

 

    测试 修改

sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

  重启nginx服务

systemctl restart nginx.service

 

 

参考文档:

flask url_for 图片URL 缺少端口号

原文地址:https://www.cnblogs.com/kaerxifa/p/11904835.html