[英]Starting http-server on Amazon EC2
I'm trying to setup and access a simple Python http-server on an Amazon EC2 instance. 我正在尝试在Amazon EC2实例上设置和访问简单的Python http服务器。 The server works locally under localhost:80, but I cannot get it to work on the EC2 instance.
服务器在localhost:80下本地工作,但我不能让它在EC2实例上工作。
I connected an elastic IP to the instance, and it at least works to access ssh on that IP. 我将弹性IP连接到实例,它至少可以访问该IP上的ssh。
I think the problem is that I'm setting the server_address for the HTTPServer incorrectly: Python HTTPServer documentation Since I really don't have a clue, at home I configured the router to forward HTTP requests to the computer's local IP, 192.168.1.xx 我认为问题是我正在为HTTPServer错误地设置server_address: Python HTTPServer文档因为我真的没有线索,所以在家里我配置路由器将HTTP请求转发到计算机的本地IP,192.168.1。 XX
I thought that it might be a security group issue, so I added inbound HTTP with source 0.0.0.0/0 (which I thought should allow all incoming IPs) and sets port 80 without any option to change. 我认为它可能是一个安全组问题,所以我添加了入口HTTP和源0.0.0.0/0(我认为应该允许所有传入的IP)并设置端口80而无需任何更改选项。
Additionally, I think that running the server script under sudo on port 80 is a potential security risk. 另外,我认为在端口80上运行sudo下的服务器脚本存在潜在的安全风险。 Is there any way to forward the request under another port like 8080 instead of 80?
有没有办法在8080而不是80的另一个端口下转发请求?
For the security group, you can create a rule that allows port 8080 (Do "Custome TCP Rule", then put 8080 for the port range). 对于安全组,您可以创建允许端口8080的规则(执行“Custome TCP规则”,然后将8080设置为端口范围)。
It sounds likely that your HTTPServer is binding to loopback. 听起来您的HTTPServer可能绑定到环回。 I would set the address to 0.0.0.0 (all interfaces), set the port to 8080, and open 8080 on your security group.
我将地址设置为0.0.0.0(所有接口),将端口设置为8080,并在安全组上打开8080。
From a security point of view it might be better to run your script behind a regular http server. 从安全角度来看,在常规http服务器后面运行脚本可能会更好。
Here is a configuration for NginX that should get you started (puth this file in /etc/nginx/conf.d/
): 下面是一个配置的Nginx应该让你开始说(北医三院这个文件中
/etc/nginx/conf.d/
):
upstream myscript {
server localhost:8080;
}
server {
server_name _;
listen 80;
location = / {
proxy_pass http://myscript;
}
}
In this setting, you run your script on port 8080 (use server_address = ('localhost', 8080)
to configure your HTTPServer
in your python script). 在此设置中,您在端口8080上运行脚本(使用
server_address = ('localhost', 8080)
在python脚本中配置HTTPServer
)。
So when a query hits nginx on port 80 it forwards it to localhost port 8080 where your script takes in charge. 因此,当查询在端口80上访问nginx时,它会将其转发到您的脚本负责的localhost端口8080。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.