更新2多克爾遠程主機
我配置configure_blueprints從create_app打電話給我的路線上瓶uwsgi 404。我不想把所有的視圖處理器放在uwsgi.py中。它們存儲在單獨的模塊中。
def configure_blueprints(app):
from .root import root_bp
...
blueprints = [
(root_bp, None),
...
]
for bp, endpoint in blueprints:
app.register_blueprint(bp, url_prefix=endpoint)
return app
def create_app(config_fn=None):
app = Flask(__name__, template_folder='../templates', static_folder='../static')
...
configure_blueprints(app)
return app
應用程序/根/ views.py
root_bp = Blueprint('root_bp', __name__)
@root_bp.route('/')
def root():
if not current_user.is_authenticated:
return redirect('/login/')
return render_template('index.html')
以下爲SIMPLE_SETTINGS=app.config,instance.docker python3 manage.py list_routes
2017-03-01 06:48:11,381 - passlib.registry - DEBUG - registered 'sha512_crypt' handler: <class 'passlib.handlers.sha2_crypt.sha512_crypt'>
...
root_bp.root HEAD,OPTIONS,GET /
...
輸出這是實施list_routes
命令
@manager.command
def list_routes():
import urllib
output = []
for rule in flask.current_app.url_map.iter_rules():
options = {}
for arg in rule.arguments:
options[arg] = '[{0}]'.format(arg)
methods = ','.join(rule.methods)
try:
url = flask.url_for(rule.endpoint, **options)
except BaseException as e:
print('Exc={}'.format(e))
line = urllib.parse.unquote('{:50s} {:20s} {}'.format(rule.endpoint, methods, url))
output.append(line)
for line in sorted(output):
print(line)
我做n個不理解爲什麼路線應該放置到文件中,並且不能動態配置。如果這不起作用,我該怎麼辦?
更新
uwsgi.ini
[uwsgi]
env = SIMPLE_SETTINGS=app.config,instance.docker
callable = app
wsgi-file = /var/www/app/uwsgi.py
uid = www-data
gid = www-data
socket = /var/www/app/uwsgi.sock
chmod-socket = 666
logto = /var/log/uwsgi/app/app.log
chdir = /var/www/app
plugin = python3
master = true
processes = 1
/var/www/app/uwsgi.py
from app import create_app
app = create_app()
我配置create_app函數內部藍圖。我認爲他們應該在申請開始時提供。我也使用Flask腳本。
SIMPLE_SETTINGS=app.config,instance.docker python3 manage.py shell
shell啓動時沒有錯誤。
原帖
我研究過的所有相關問題。我無法解決我的問題。我通過遠程主機上的docker-machine部署我的項目。下面是我的配置:
Dockerfile
FROM ubuntu:latest
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8
RUN apt-get update && apt-get install -y \
python3 python3-pip git libpq-dev libevent-dev uwsgi-plugin-python3 \
nginx supervisor
COPY nginx/flask.conf /etc/nginx/sites-available/
COPY supervisor/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY . /var/www/app
RUN mkdir -p /var/log/nginx/app /var/log/uwsgi/app /var/log/supervisor \
&& rm /etc/nginx/sites-enabled/default \
&& ln -s /etc/nginx/sites-available/flask.conf /etc/nginx/sites-enabled/flask.conf \
&& echo "daemon off;" >> /etc/nginx/nginx.conf \
&& pip3 install -r /var/www/app/python_modules \
&& chown -R www-data:www-data /var/www/app \
&& chown -R www-data:www-data /var/log
WORKDIR /var/www/app
CMD ["/usr/bin/supervisord"]
泊塢窗,compose.yml
version: '2'
services:
db:
image: postgres
volumes:
- moderator-db:/var/lib/postgresql/data
redis:
image: redis
rabbitmq:
image: rabbitmq:3.6
api:
build: .
mem_limit: 1000m
ports:
- "80:80"
depends_on:
- redis
- db
- rabbitmq
volumes:
moderator-redis:
driver: local
moderator-db:
driver: local
supervisord.conf
[supervisord]
nodaemon=true
[program:nginx]
command=/usr/sbin/nginx
[program:uwsgi]
command=uwsgi --ini /var/www/app/uwsgi.ini
瓶的nginx的conf
server {
server_name localhost;
listen 80 default_server;
charset utf-8;
sendfile on;
client_max_body_size 70M;
keepalive_timeout 0;
proxy_buffering on;
proxy_buffer_size 8k;
proxy_buffers 2048 8k;
proxy_ignore_client_abort on;
location/{
include uwsgi_params;
uwsgi_pass unix:///var/www/app/uwsgi.sock;
}
location /static {
root /var/www/app/static/;
}
}
$搬運工PS
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d9dec354d97e moderator_api "/usr/bin/supervisord" 13 seconds ago Up 9 seconds 0.0.0.0:80->80/tcp moderator_api_1
243c48dac303 postgres "docker-entrypoint..." 3 hours ago Up 14 seconds 5432/tcp moderator_db_1
23901a761ef1 redis "docker-entrypoint..." 3 hours ago Up 14 seconds 6379/tcp moderator_redis_1
7cc0683bfe18 rabbitmq:3.6 "docker-entrypoint..." 3 hours ago Up 16 seconds 4369/tcp, 5671-5672/tcp, 25672/tcp moderator_rabbitmq_1
尾-f /var/log/uwsgi/app/app.log
[pid: 24|app: 0|req: 1/1] 123.23.7.216() {44 vars in 945 bytes} [Tue Feb 28 14:53:57 2017] GET/=> generated 233 bytes in 10 msecs (HTTP/1.1 404) 3 headers in 311 bytes (1 switches on core 0)
如果您需要任何額外的信息,請讓我知道。我嘗試了不同的配置:nginx-proxy image,gunicorn等。我對遠程主機有同樣的問題。我還缺少什麼?
即時通訊沒有碼頭專家,但如果其確認'200'從碼頭機內檢查'iptables'確保您正在接受流 – Busturdust
請分享文件uwsgi.ini文件的內容太 –
@Busturdust我可以看到我的請求在應用程序日誌文件中,它看起來像請求來到應用程序 – theodor