Django:错误:您无权访问该端口 [英] Django: Error: You don't have permission to access that port

查看:80
本文介绍了Django:错误:您无权访问该端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对整个设置很陌生,所以请保持友善.在 dev 上,该命令通常可以正常工作,但由于我一直在为 Django 尝试不同的命令,所以出现了错误.

I'm very new to this whole setup so please be nice. On dev the command usually works with no errors but since I have been experimenting with different commands for Django someting has gone wrong.

python manage.py runserver 0.0.0.0:80

我无权再使用此端口.我可以使用端口 8080,但是当我将该端口添加到 url 中常用主机名的末尾时,该网站不起作用.当我使用端口 80 时,无论如何我都不必在 url 中添加 :80.

I don't have permission to use this port anymore. I can use port 8080 but the website doesn't work when I add the port to the end of the usual host name in the url. When I used port 80 I never had to add :80 to the url anyway.

我有一个错误,我没有日志文件的权限,但我更改了该文件的权限.看来现在有很多事情我没有权限.

I had an error where I didn't have permissions to the log file but I changed the permissions on that file. It seems there is now many things I don't have permissions for.

Django 1.8.5.使用虚拟环境,我在项目中有 2 个应用.

Django 1.8.5. Using a virtual envirnment and I have 2 apps in the project.

推荐答案

如果您使用的是 Linux,则会收到此错误.

If you're on Linux, you'll receive this error.

首先,Django 没有生产服务器,只是一个非常基本的开发服务器,默认使用端口 8080.

First and foremost, Django does not have a production server, just a very basic development server and uses port 8080 by default.

当你执行命令时

python manage.py runserver

您告诉 django 启动其开发服务器并运行,以便您可以在部署到生产服务器之前测试您的 Web 应用程序.

you tell django to start its development server and it runs so you can test your web app before deployment to a production server.

Django 文档 -> django-admin -> 运行服务器

访问服务器的方式是使用浏览器在地址栏中插入网址

The way to access the server is to use your browser and plug in the URL in the address bar as so

localhost:8080

默认情况下,除非另有说明,否则大多数 HTTP 应用程序都在端口 80 上运行.例如,默认情况下,您的 MySQL 服务器可以在端口 3306 上运行.

by default, most HTTP applications run on port 80 unless otherwise stated. For example, your MySQL server could run on port 3306 by default.

基本上,您可以将端口视为老式电话线,将您与您希望与之交流的人连接起来.

Basically, you can think of ports as old school telephone lines that connect you to whom ever your looking to communicate with.

这一切都没有什么特别之处.您可能应该先玩一下瓶子以了解基础知识;只是一个友好的建议.

There's nothing really special about any of this. You should probably play with bottle to get the basics down first; just a friendly suggestion.

您可以在网站上深入了解详情.虽然不安全,您可以使用 sudo 在端口 80 上运行,但出于安全原因,您应该避免使用它.

You can dig in to the details on the website. While not secure, you can use sudo to run on port 80, but for security reasons you should avoid it.

@mtt2p 提到了一个 serverfault 帖子很好地说明了原因

@mtt2p mentions a serverfault post that does a great job of the why

我确信有一种方法可以告诉服务器只允许本地连接,但是当您想向其他人展示您的工作或查看您的网络应用程序的外观时,您应该只使用 0.0.0.0:80其他设备.

I'm sure there's a way to tell the server to allow only local connections, but you should only use 0.0.0.0:80 when you want to show off your work to other people or see what your web app looks like on other devices.

从长远来看,sudo 只是更简单、更快捷,但很懒惰且不安全.

In the long run, sudo is just easier and quicker, but lazy and insecure.

这是一个在 virtualenv 上下文中解释它的链接.

This is a link that explains it in the context of a virtualenv.

指定端口时Django运行服务器出错

答案说明

我猜 sudo 命令将在超级用户中运行该进程上下文,并且超级用户上下文缺少 virtualenv 设置.

I guess the sudo command will run the process in the superuser context, and the superuser context lack virtualenv settings.

制作一个shell脚本来设置virtualenv并调用manage.pyrunserver,然后改为 sudo 这个脚本.

Make a shell script to set the virtualenv and call manage.py runserver, then sudo this script instead.

您应该注意到解释基于 virtualenv 的上下文的答案也是不安全的.它应该只是运行

You should note that the answer explaining a virtualenv based context is also insecure. It should just be run as

sudo python manage.py runserver 80

不是

sudo bash script-name

在 vi​​rtualenv 之外.这样做违背了对应用程序进行沙盒处理的目的.如果您忽略这一点,您将面临竞争条件.

outside of a virtualenv. Doing so defeats the purpose of sand-boxing your application. If you ignore this, you'll be exposing yourself to a race condition.

这篇关于Django:错误:您无权访问该端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆