设置一个子域名以指向同一数字海洋水滴上的 Flask 应用程序(使用 Ubuntu 15.10 上的 uwsgi 和 nginx)

设置一个子域名以指向同一数字海洋水滴上的 Flask 应用程序(使用 Ubuntu 15.10 上的 uwsgi 和 nginx)

我有一个名为 abc.com 的域名,它指向一个静态 html 页面/var/www/abc.com/public_html

我想在同一个 droplet(也许是不同的端口?)上托管一个 Flask 应用程序,可以使用子域 demo.abc.com 访问。

我遵循指示这里, 和这里,但它们现在似乎对我来说不起作用。

以下是我的区域文件目前的样子

$ORIGIN abc.com.
$TTL 1800
abc.com. IN SOA ns1.digitalocean.com. hostmaster.abc.com. 1451918078 10800 3600 604800 1800
abc.com. 1800 IN NS ns1.digitalocean.com.
abc.com. 1800 IN NS ns2.digitalocean.com.
abc.com. 1800 IN NS ns3.digitalocean.com.
abc.com. 1800 IN A 111.222.333.44
*.abc.com. 1800 IN CNAME abc.com.

我在 /var/www/demo.abc.com/ 创建了一个 app.py,其中有

from flask import Flask
application = Flask(__name__)

@application.route("/")
def hello():
    return 'Hello World!'

if __name__ == "__main__":
    application.run(host='0.0.0.0')

我在 /etc/nginx/sites-available 中有 3 个文件 -

默认

美国广播公司

demo.abc.com

其中只有abc.comdemo.abc.com符号链接到/etc/nginx/sites-enabled

demo.abc.com 的样子如下:

server {
    listen 80;
    server_tokens off;
    server_name demo.abc.com;

     location / {
         include uwsgi_params;
         uwsgi_pass unix:/tmp/demo.sock;
     }

     location /static {
         alias /var/www/demo.abc.com/static;
     }

     ## Only requests to our Host are allowed
     if ($host !~ ^(demo.abc.com.com|www.demo.abc.com)$ ) {
        return 444;
     }
}

abc.com 的样子如下:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/abc.com/public_html;

        server_name abc.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;

                # With php5-cgi alone:
                #fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
}

这是默认的:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
}

/etc/uwsgi/apps-available/demo.abc.com.ini 如下所示

[uwsgi]
vhost = true
socket = /tmp/demo.sock
venv = /var/www/demo.abc.com/.env
chdir = /var/www/demo.abc.com
module = app
callable = application

master = true
processes = 5

chmod-socket = 660
vacuum = true

die-on-term = true

abc.com 运行正常,而 demo.abc.com 未运行。启动服务 nginx 和 uwsgi 时没有出现任何错误。但是我对它们都是新手。请指导我我做错了什么。

编辑

附加完整uwsgi 日志和 nginx访问日志(第二个是 88 MB)。我不确定如何只获取日志中失败的请求部分。据我了解,它们看起来像这样 -

uwsgi.log

Sun Jan 17 07:54:58 2016 - *** Starting uWSGI 2.0.7-debian (64bit) on [Sun Jan 17 07:54:58 2016] ***
Sun Jan 17 07:54:58 2016 - compiled with version: 5.2.1 20150903 on 08 September 2015 19:33:31
Sun Jan 17 07:54:58 2016 - os: Linux-4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015
Sun Jan 17 07:54:58 2016 - nodename: Poolka.com
Sun Jan 17 07:54:58 2016 - machine: x86_64
Sun Jan 17 07:54:58 2016 - clock source: unix
Sun Jan 17 07:54:58 2016 - pcre jit disabled
Sun Jan 17 07:54:58 2016 - detected number of CPU cores: 1
Sun Jan 17 07:54:58 2016 - current working directory: /
Sun Jan 17 07:54:58 2016 - writing pidfile to /run/uwsgi/app/demo.poolka.com/pid
Sun Jan 17 07:54:58 2016 - detected binary path: /usr/bin/uwsgi-core
Sun Jan 17 07:54:58 2016 - setgid() to 33
Sun Jan 17 07:54:58 2016 - setuid() to 33
Sun Jan 17 07:54:58 2016 - your processes number limit is 1833
Sun Jan 17 07:54:58 2016 - your memory page size is 4096 bytes
Sun Jan 17 07:54:58 2016 - detected max file descriptor number: 1024
Sun Jan 17 07:54:58 2016 - VirtualHosting mode enabled.
Sun Jan 17 07:54:58 2016 - lock engine: pthread robust mutexes
Sun Jan 17 07:54:58 2016 - thunder lock: disabled (you can enable it with --thunder-lock)
Sun Jan 17 07:54:58 2016 - uwsgi socket 0 bound to UNIX address /run/uwsgi/app/demo.poolka.com/socket fd 3
Sun Jan 17 07:54:58 2016 - uwsgi socket 1 bound to UNIX address /tmp/demo.sock fd 5
Sun Jan 17 07:54:58 2016 - Python version: 2.7.10 (default, Oct 14 2015, 16:09:02)  [GCC 5.2.1 20151010]
Sun Jan 17 07:54:58 2016 - Set PythonHome to /var/www/demo.poolka.com/.env
Sun Jan 17 07:54:58 2016 - *** Python threads support is disabled. You can enable it with --enable-threads ***
Sun Jan 17 07:54:58 2016 - Python main interpreter initialized at 0x1f08d00
Sun Jan 17 07:54:58 2016 - your server socket listen backlog is limited to 100 connections
Sun Jan 17 07:54:58 2016 - your mercy for graceful operations on workers is 60 seconds
Sun Jan 17 07:54:58 2016 - mapped 436608 bytes (426 KB) for 5 cores
Sun Jan 17 07:54:58 2016 - *** Operational MODE: preforking ***
Sun Jan 17 07:54:58 2016 - WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1f08d00 pid: 17624 (default app)
Sun Jan 17 07:54:58 2016 - *** uWSGI is running in multiple interpreter mode ***
Sun Jan 17 07:54:58 2016 - spawned uWSGI master process (pid: 17624)
Sun Jan 17 07:54:58 2016 - spawned uWSGI worker 1 (pid: 17632, cores: 1)
Sun Jan 17 07:54:58 2016 - spawned uWSGI worker 2 (pid: 17633, cores: 1)
Sun Jan 17 07:54:58 2016 - spawned uWSGI worker 3 (pid: 17634, cores: 1)
Sun Jan 17 07:54:58 2016 - spawned uWSGI worker 4 (pid: 17635, cores: 1)
Sun Jan 17 07:54:58 2016 - spawned uWSGI worker 5 (pid: 17636, cores: 1)

访问日志

14.183.60.220 - - [17/Jan/2016:13:38:52 -0500] "GET /items?c=37008&ts=1426138782918&m=20&T= HTTP/1.1" 404 177 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
86.129.146.109 - - [17/Jan/2016:13:38:52 -0500] "GET /items?c=6006&ts=1427056285299&m=30&T= HTTP/1.1" 404 177 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
86.129.146.109 - - [17/Jan/2016:13:38:52 -0500] "GET /items?c=48005&ts=1397342348934&m=30&T= HTTP/1.1" 404 177 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
14.183.60.220 - - [17/Jan/2016:13:38:52 -0500] "GET /items?c=28006&ts=1409495783294&m=20&T= HTTP/1.1" 404 177 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
14.183.60.220 - - [17/Jan/2016:13:38:52 -0500] "GET /items?c=20008&ts=1426240752454&m=20&T= HTTP/1.1" 404 177 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
31.18.246.156 - - [17/Jan/2016:13:38:52 -0500] "GET /items?c=6008&ts=1427052397699&m=10&T= HTTP/1.1" 404 177 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
31.18.246.156 - - [17/Jan/2016:13:38:52 -0500] "GET /items?c=41008&ts=1423783986283&m=10&T= HTTP/1.1" 404 177 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
31.18.246.156 - - [17/Jan/2016:13:38:52 -0500] "GET /items?c=23008&ts=1427067411049&m=10&T= HTTP/1.1" 404 177 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
14.183.60.220 - - [17/Jan/2016:13:38:52 -0500] "GET /items?c=37009&ts=1426108634237&m=20&T= HTTP/1.1" 404 177 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
14.183.60.220 - - [17/Jan/2016:13:38:52 -0500] "GET /items?c=46001&ts=1409495784000&m=20&T= HTTP/1.1" 404 177 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
14.183.60.220 - - [17/Jan/2016:13:38:52 -0500] "GET /items?c=20009&ts=1426224478835&m=20&T= HTTP/1.1" 404 177 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
14.183.60.220 - - [17/Jan/2016:13:38:52 -0500] "GET /items?c=11001&ts=1426240749118&m=20&T= HTTP/1.1" 404 177 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"

相关内容