访问gunicorn flask服务器时不指定端口名称

2024-05-18 01:37:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个小博客烧瓶应用程序。我这样执行这个应用程序:

$ gunicorn gunluk:app -p gunluk.pid -b 0.0.0.0:8000

我可以这样访问它:

http://programlama.tk:8000/

但我想做的是在不指定端口名的情况下访问站点:

http://programlama.tk

当前ip表规则列表:

$ sudo iptables -nvL

Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
   62  7092 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8000
  593 67706 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8080
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:5000
 3631 3641K ACCEPT     all  --  enp1s0 *       0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8000

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
  655 74798 ACCEPT     all  --  *      lo      0.0.0.0/0            0.0.0.0/0
 2790  322K ACCEPT     all  --  *      enp1s0  0.0.0.0/0            0.0.0.0/0

路由器接口中的端口转发设置如下:

^{pr2}$

我没有静态ip,我使用一个带有动态ip地址的免费动态dns服务。在


Tags: inipchaintargetbytespolicyallout
1条回答
网友
1楼 · 发布于 2024-05-18 01:37:06

这是一个需要处理的nginx事情。在

server {
listen 80;  # listen onport 80
server_name server_domain_or_IP; #requests to this domain or ip

location / {
    include proxy_params;
    proxy_pass http://unix:<fullpath-to-your-project>.sock;
   }
}

这将反转server_name:80到应用程序的url:port的所有流量

您可以创建一个daemon,让您的Gunicorn在系统重新启动时自动运行。在

相关问题 更多 >