Python 在生产服务器上工作的端口值应该是多少?

Python 在生产服务器上工作的端口值应该是多少?,python,django,google-api-python-client,Python,Django,Google Api Python Client,在本地机器上开发时,我使用standart代码来授权和使用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 fo

在本地机器上开发时,我使用standart代码来授权和使用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作为端口参数值。这很有效。在生产服务器上部署项目时,我收到一条消息
端口已在使用中

服务器:Ubuntu18.04,Nginx,uwsgi

我应该使用什么值

UPD

我已将端口更改为5000,所有操作都在本地计算机上进行。我试图在生产服务器上运行它,但出现了504错误。我检查了uwsgi日志,发现文件的末尾包含一个指向授权的链接。
在本地计算机上,此链接会自动在新窗口中打开以登录到帐户。如果再次尝试运行生产服务器,我将获得已在使用的[Errno 98]地址错误,此错误将保存到重新启动uwsgi。重新启动后,一切都会再次重复。

请尝试netstat查看正在使用的端口

netstat-an | grep LISTEN

Proto Recv-Q Send-Q本地地址外部地址状态
tcp 0.0.0.0:80 0.0.0.0:*听

返回的任何端口都会显示上面的错误“端口已在使用”。 任何其他端口都可以工作。 出于安全原因,最好使用1024以上的端口和非特权用户。django经常使用端口8000或端口8888,但可以使用任何端口

你也可以使用插座


端口8078、8079和8080通常由tomcat/jetty等应用服务器使用。

在生产过程中,您将使用一些
wsgi
服务器在
nginx/apache
服务器和应用程序之间进行调解。然后服务器(apache/nginx)将在80/443上运行和处理请求:)@hansolo这是否意味着我需要使用端口80的值?如果它与任何其他服务不冲突,您可以使用任何端口。nginx的默认端口是80,但您可以在应用程序的nginx conf文件中指定它,只需确保在djangoI try 8079和8081中指定了相同的端口,但结果是sameI尝试了许多不同的端口含义,每个人都有相同的问题。我认为这里的问题不是具体意义上的。重新启动uwsgi后,会尝试进行授权(即接受端口值),但不会发生引用OAuth2的重定向。非常奇怪的是,当重试时,错误
[Errno 98]地址已在使用中
sudo systemctl start uwsgi
我有一个systemd单元文件来管理uwsgi进程并在bootI自动启动uwsgi。我添加了我的uwsgi.service配置来提问。看起来您需要将端口8080更改为未使用的端口。如果您运行netstat,它将给出您正在侦听的端口的列表-这些端口都将给出一个错误。任何其他端口都可以工作。