質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Bottle

Bottleは、PythonのWebサーバです。1つのPythonファイルで構成されており、非常に軽量。Web APIの作成や導入が簡単で、DjangoやFlaskに比べ使いやすくシンプルなことが特徴です。

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

1回答

3193閲覧

Python - bottle+nginx+uwsgiで「データが受信されませんでした」

Miz21358

総合スコア13

Bottle

Bottleは、PythonのWebサーバです。1つのPythonファイルで構成されており、非常に軽量。Web APIの作成や導入が簡単で、DjangoやFlaskに比べ使いやすくシンプルなことが特徴です。

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2017/03/05 09:08

###前提・実現したいこと

bottle+nginx+uwsgiでwebアプリケーションを作成したいです。
既にnginxでkibanaを動かしており、それと同居させたいです。

###発生している問題・エラーメッセージ

--2017-03-05 17:42:33-- (試行: 3) http://localhost:8080/python localhost (localhost)|127.0.0.1|:8080 に接続しています... 接続しました。 HTTP による接続要求を送信しました、応答を待っています... データが受信されませんでした 再試行しています。

###現在の設定等状況

  1. nginx
error_log /var/log/nginx/hoge.error.log warn; # basic authentification for kibana upstream kibana { server localhost:5601; } upstream python { #server unix:///run/uwsgi/app/hoge/socket/bottle.socket; server 127.0.0.1:8080; } server{ listen 80 default; server_name hoge.mydns.jp; error_log /var/log/nginx/nginx_hoge.error.log warn; access_log /var/log/nginx/nginx_hoge.access.log; location / { stub_status on; root /var/www/html/; index index.nginx-debian.html; } location /python/ { stub_status on; include /etc/nginx/uwsgi_params; uwsgi_pass python; } location ~ (/app/kibana|/bundles/|/status|/elasticsearch|/plugins|/timelion|/console) { stub_status on; auth_basic "Restricted"; auth_basic_user_file "/etc/nginx/.htpasswd"; proxy_pass http://kibana; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $http_host; } location ~ \.css { add_header Content-Type text/css; } location ~ \.js { add_header Content-Type application/x-javascript; } }
root@user:~/app# service nginx status ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since 日 2017-03-05 17:38:32 JST; 19min ago Process: 31373 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exit Process: 31383 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 31375 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS Main PID: 31385 (nginx) CGroup: /system.slice/nginx.service ├─31385 nginx: master process /usr/sbin/nginx -g daemon on; master_process on ├─31386 nginx: worker process └─31387 nginx: worker process 3月 05 17:38:32 user systemd[1]: Starting A high performance web server and a reverse proxy server... 3月 05 17:38:32 user systemd[1]: Started A high performance web server and a reverse proxy server.
  1. uwsgi
[uwsgi] master = true #plugin = python chdir = /var/www/python/python/ file = app.py #socket = /run/uwsgi/app/hoge/socket/bottle.socket socket = :8080 pidfile = /run/uwsgi/app/hoge/pid/bottle.pid chmod-socket = 666 uid = www-data gid = www-data buffer-size = 65535 #log log-x-forwarded-for = true log-format = %(addr) - %(user) [%(ltime)] "(method) %(uri) %(proto)" %(status) %(size)<code></code> "%(referer)" "%(uagent)" logto = /var/log/uwsgi/uwsgi.log
root@user:/etc/uwsgi/apps-available# uwsgi --ini myapp.ini [uWSGI] getting INI configuration from myapp.ini
*** Starting uWSGI 2.0.14 (32bit) on [Sun Mar 5 17:59:30 2017] *** compiled with version: 5.4.0 20160609 on 04 March 2017 14:06:55 os: Linux-4.4.0-64-generic #85-Ubuntu SMP Mon Feb 20 11:49:39 UTC 2017 nodename: user machine: i686 clock source: unix pcre jit disabled detected number of CPU cores: 2 current working directory: /etc/uwsgi/apps-available writing pidfile to /run/uwsgi/app/hoge/pid/bottle.pid detected binary path: /usr/local/bin/uwsgi setgid() to 33 setuid() to 33 chdir() to /var/www/python/python/ your processes number limit is 32041 your memory page size is 4096 bytes detected max file descriptor number: 1024 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uwsgi socket 0 bound to TCP address :8080 fd 3 Python version: 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] *** Python threads support is disabled. You can enable it with --enable-threads *** Python main interpreter initialized at 0x911c868 your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 250854 bytes (244 KB) for 1 cores *** Operational MODE: single process *** WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x911c868 pid: 31711 (default app) *** uWSGI is running in multiple interpreter mode *** spawned uWSGI master process (pid: 31711) spawned uWSGI worker 1 (pid: 31712, cores: 1)
  1. app.py
root@user:/var/www/python/python# pwd /var/www/python/python root@user:/var/www/python/python# cat app.py #!/usr/bin/env python # -*- coding:utf-8 -*- import logging import bottle @bottle.route('/python')# Handle HTTP GET for the application root def hello(): return bottle.template('<h1>Hello App Template</h1>\n') # Run bottle internal test server when invoked directly ie: non-uxsgi mode if __name__ == '__main__': bottle.run(host='localhost', port=8080, debug=True) # Run bottle in application mode. Required in order to get the application working with uWSGI! else: application = bottle.default_app()
  1. プロセス・ポート
root@user:~/app# lsof -i:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME metricbea 19367 root 5u IPv4 9090648 0t0 TCP localhost:34554->localhost:http (ESTABLISHED) nginx 31385 root 9u IPv4 8998095 0t0 TCP *:http (LISTEN) nginx 31386 www-data 9u IPv4 8998095 0t0 TCP *:http (LISTEN) nginx 31387 www-data 9u IPv4 8998095 0t0 TCP *:http (LISTEN) nginx 31387 www-data 10u IPv4 9090649 0t0 TCP localhost:http->localhost:34554 (ESTABLISHED) root@user:~/app# lsof -i:8080 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME uwsgi 31711 www-data 3u IPv4 9113003 0t0 TCP *:http-alt (LISTEN) uwsgi 31712 www-data 3u IPv4 9113003 0t0 TCP *:http-alt (LISTEN)

お手数をおかけして申し訳ありませんが、ご助力のほど、よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

server_name hoge.mydns.jp;

これはHOSTヘッダにhoge.mydns.jpが設定されているサーバ設定なのでnginxではじかれると思います。開発中はserver_nameに_を設定しておくケースが多いと思います。

server_name _;

それからnginxのlistenはポート80になっているので、http://localhost:8080/pythonではなくて、http://localhost:80/pythonにアクセスしてください。8080はHTTPではなくて[uwsgi Protocol](http://uwsgi-docs.readthedocs.io/en/latest/Protocol.html)なので専用のものでないと話せないと思います。

NGINX: Server names

投稿2017/03/05 17:48

sharow

総合スコア1149

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問