乡土老农 发表于 2024-6-25 15:40:37

【待反馈】python项目 端口占用问题

为了能快速了解并处理您的问题,请提供以下基础信息:面板、插件版本:8.2.0
系统版本:Ubuntu 22.04.4 LTS
问题描述:新建python项目后,端口设为6000,但是启动时还是在5000,这样新建的python项目就总是端口被占用:

项目日志:
* Serving Flask app 'app' * Debug mode: onAddress already in usePort 5000 is in use by another program. Either identify and stop that program, or start the server with a different port.
相关截图(日志、错误):

乡土老农 发表于 2024-6-25 15:42:45

好像是最早用了5000端口,后面再设置其他端口都没用了。
# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address         Foreign Address         State       PID/Program name   
tcp      0      0 127.0.0.1:5000          0.0.0.0:*               LISTEN      358621/python3      
tcp      0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      358345/nginx: maste
tcp      0      0 0.0.0.0:80            0.0.0.0:*               LISTEN      358345/nginx: maste
tcp      0      0 0.0.0.0:22            0.0.0.0:*               LISTEN      218232/sshd: /usr/s
tcp      0      0 0.0.0.0:888             0.0.0.0:*               LISTEN      358345/nginx: maste
tcp      0      0 127.0.0.53:53         0.0.0.0:*               LISTEN      218358/systemd-reso
tcp      0      0 0.0.0.0:34648         0.0.0.0:*               LISTEN      244282/python3      
tcp      0      0 127.0.0.1:1080          0.0.0.0:*               LISTEN      218555/ssh         
tcp6       0      0 :::33060                :::*                  LISTEN      247104/mysqld      
tcp6       0      0 ::1:1080                :::*                  LISTEN      218555/ssh         
tcp6       0      0 :::3306               :::*                  LISTEN      247104/mysqld

运维技术阿闯 发表于 2024-6-25 16:14:01

乡土老农 发表于 2024-6-25 15:42
好像是最早用了5000端口,后面再设置其他端口都没用了。
# netstat -ntlp
Active Internet connections (on ...

您好,您这边是用过网站-python项目创建的吗,这边测试通过python项目创建的两个项目一个453端口一个6000端口,均未出现问题
您这边也是通过网站-python项目创建的项目的话,请将您创建的时候的配置截图一下

乡土老农 发表于 2024-6-25 16:31:06

我在另一台服务器上也复现了这个过程,新建python站点,端口设置成6000,但是netstat和日志里看到的就是启动了5000端口:
* Serving Flask app 'app'
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on https://127.0.0.1:5000
Press CTRL+C to quit
* Restarting with stat
* Debugger is active!
* Debugger PIN: 114-917-419

乡土老农 发表于 2024-6-25 16:34:05


运维技术阿闯 发表于 2024-6-25 17:46:25

乡土老农 发表于 2024-6-25 16:34

您好,使用python项目请前往【网站->Python项目】,目前python项目管理器已经不再维护了

乡土老农 发表于 2024-6-25 18:56:03

我就是在这啊

运维技术阿闯 发表于 2024-6-26 09:39:37

乡土老农 发表于 2024-6-25 18:56
我就是在这啊

您好,您这边停止5000端口后开启6000端口,并将netstat和日志信息发一下

乡土老农 发表于 2024-6-26 12:30:51

一、查看端口:root@youshu:~# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address         Foreign Address         State       PID/Program name   
tcp      0      0 127.0.0.1:5000          0.0.0.0:*               LISTEN      358621/python3      
tcp      0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      358345/nginx: maste
tcp      0      0 0.0.0.0:80            0.0.0.0:*               LISTEN      358345/nginx: maste
tcp      0      0 0.0.0.0:22            0.0.0.0:*               LISTEN      218232/sshd: /usr/s
tcp      0      0 0.0.0.0:888             0.0.0.0:*               LISTEN      358345/nginx: maste
tcp      0      0 127.0.0.53:53         0.0.0.0:*               LISTEN      218358/systemd-reso
tcp      0      0 0.0.0.0:34648         0.0.0.0:*               LISTEN      244282/python3      
tcp      0      0 127.0.0.1:1080          0.0.0.0:*               LISTEN      218555/ssh         
tcp6       0      0 :::33060                :::*                  LISTEN      247104/mysqld      
tcp6       0      0 ::1:1080                :::*                  LISTEN      218555/ssh         
tcp6       0      0 :::3306               :::*                  LISTEN      247104/mysqld      
二、杀死5000端口 root@youshu:~# kill 358621
root@youshu:~# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address         Foreign Address         State       PID/Program name   
tcp      0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      358345/nginx: maste
tcp      0      0 0.0.0.0:80            0.0.0.0:*               LISTEN      358345/nginx: maste
tcp      0      0 0.0.0.0:22            0.0.0.0:*               LISTEN      218232/sshd: /usr/s
tcp      0      0 0.0.0.0:888             0.0.0.0:*               LISTEN      358345/nginx: maste
tcp      0      0 127.0.0.53:53         0.0.0.0:*               LISTEN      218358/systemd-reso
tcp      0      0 0.0.0.0:34648         0.0.0.0:*               LISTEN      244282/python3      
tcp      0      0 127.0.0.1:1080          0.0.0.0:*               LISTEN      218555/ssh         
tcp6       0      0 :::33060                :::*                  LISTEN      247104/mysqld      
tcp6       0      0 ::1:1080                :::*                  LISTEN      218555/ssh         
tcp6       0      0 :::3306               :::*                  LISTEN      247104/mysqld   

三、查看python项目设置,端口6000,启动,查看netstat:
* Serving Flask app 'app'
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on https://127.0.0.1:5000
Press CTRL+C to quit
* Restarting with stat
* Debugger is active!
* Debugger PIN: 124-357-060

四、项目日志:
* Serving Flask app 'app'
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on https://127.0.0.1:5000
Press CTRL+C to quit
* Restarting with stat
* Debugger is active!
* Debugger PIN: 124-357-060

乡土老农 发表于 2024-6-26 12:32:00

网站日志:
ip - - "GET / HTTP/1.1" 502 150 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0"
ip - - "HEAD / HTTP/1.1" 502 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0"

乡土老农 发表于 2024-6-26 12:33:34

程序我已经着了台新的服务器,允许它”任性“地占有5000端口,跑起来没问题,但就是不能改端口,设置界面改了。跑则还是5000,且报502 Bad Gateway

运维技术阿闯 发表于 2024-6-26 14:46:33

乡土老农 发表于 2024-6-26 12:33
程序我已经着了台新的服务器,允许它”任性“地占有5000端口,跑起来没问题,但就是不能改端口,设置界面改 ...

您好,您这边方便后台私信我您的面板信息吗,我这边需要在您机器上测试创建一个python项目来看一下

乡土老农 发表于 2024-6-26 15:30:51

好的
我发给您

运维技术阿闯 发表于 2024-6-26 15:40:13

乡土老农 发表于 2024-6-26 15:30
好的
我发给您

好的,已经看到了,这边测试一下

乡土老农 发表于 2024-6-26 19:11:37

咋样,是不是不行啊
页: [1] 2
查看完整版本: 【待反馈】python项目 端口占用问题