python - 在生产服务器上工作的端口值应该是多少?
问题描述
在本地机器上开发时,我使用标准代码来授权和使用 Google 磁盘
creds = None
cred = os.path.join(settings.BASE_DIR, 'credentials.json')
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
cred, SCOPES)
creds = flow.run_local_server(port=8080)
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
我使用 8080 作为端口参数值。这行得通。在生产服务器上部署项目时,我收到一条消息port is already in use
。
服务器:Ubuntu 18.04、Nginx、uwsgi
我应该使用什么值?
UPD
我已将端口更改为 5000,一切都在本地计算机上运行。我尝试在生产服务器上运行它并收到 504 错误。我检查了 uwsgi 日志,发现文件末尾包含一个授权链接。 在本地计算机上,此链接会自动在新窗口中打开以登录帐户。如果再次尝试运行生产服务器,我将收到[Errno 98] 地址已在使用错误,并且此错误会保存到重新启动 uwsgi。重新启动后,一切都会再次重演。
解决方案
尝试 netstat 查看正在使用的端口。
网络统计-an | grep 听
Proto Recv-Q Send-Q 本地地址 外部地址 状态
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
返回的任何端口都会给您上面的错误“端口已在使用中”。任何其他端口都应该工作。出于安全原因,最好使用 1024 以上的端口和非特权用户。django 经常使用端口 8000 或端口 8888,但任何端口都可以使用。
您也可以使用套接字。
端口 8078、8079 和 8080 通常由应用服务器(如 tomcat / jetty)使用。
推荐阅读
- bash - 如何在 ssh-disconnect 后终止 bash 会话以保留命令历史记录?
- python - pyspark中的unixtime到datetime
- cypress - 单击按钮不会将我定向到赛普拉斯中的预期 URL
- java - 无法使用 Jsoup 从网站上抓取价格
- javascript - 使用 Stenicl.js 修改自定义元素的轻 DOM 在 Edge 中不起作用
- konvajs - React+Konva:如何用上传的图像填充PatternImage?
- git - 从 git 中删除不在我的仓库中的文件
- javascript - 我需要从网站中选择元素“x”,但网站加载元素“x”太慢
- ruby-on-rails - 带有句点或特殊字符的 Ruby on Rails 路由
- scope - perl6 subs 真的是词法范围还是有额外的?