我已经按照this article安装了我的烧瓶应用程序。
当我检查systemd服务的状态时,得到以下信息:
appname.service - uWSGI instance to serve appname
Loaded: loaded (/etc/systemd/system/appname.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-07-16 11:02:58 UTC; 18min ago
Main PID: 15897 (uwsgi)
Tasks: 3 (limit: 1152)
CGroup: /system.slice/appname.service
├─15897 /home/appname/.local/share/virtualenvs/html-73O5c8WY/bin/uwsgi --ini /var/www/api.appname.com/html/appname.ini
├─15911 /home/appname/.local/share/virtualenvs/html-73O5c8WY/bin/uwsgi --ini /var/www/api.appname.com/html/appname.ini
└─15912 /home/appname/.local/share/virtualenvs/html-73O5c8WY/bin/uwsgi --ini /var/www/api.appname.com/html/appname.ini
Jul 16 11:02:58 appname uwsgi[15897]: Python main interpreter initialized at 0x560bda93bfa0
Jul 16 11:02:58 appname uwsgi[15897]: your server socket listen backlog is limited to 100 connections
Jul 16 11:02:58 appname uwsgi[15897]: your mercy for graceful operations on workers is 60 seconds
Jul 16 11:02:58 appname uwsgi[15897]: mapped 218760 bytes (213 KB) for 2 cores
Jul 16 11:02:58 appname uwsgi[15897]: *** Operational MODE: preforking ***
Jul 16 11:02:59 appname uwsgi[15897]: WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x560bda93bfa0 pid: 15897 (default app)
Jul 16 11:02:59 appname uwsgi[15897]: *** uWSGI is running in multiple interpreter mode ***
Jul 16 11:02:59 appname uwsgi[15897]: spawned uWSGI master process (pid: 15897)
Jul 16 11:02:59 appname uwsgi[15897]: spawned uWSGI worker 1 (pid: 15911, cores: 1)
Jul 16 11:02:59 appname uwsgi[15897]: spawned uWSGI worker 2 (pid: 15912, cores: 1)
不知道我要去哪里错,因为没有错误...
/etc/systemd/system/appname.service
[Unit]
Description=uWSGI instance to serve appname
After=network.target
[Service]
User=appname
Group=www-data
WorkingDirectory=/var/www/api.appname.com/html
Environment="PATH=/home/appname/.local/share/virtualenvs/html-73O5c8WY/bin"
ExecStart=/home/appname/.local/share/virtualenvs/html-73O5c8WY/bin/uwsgi --ini /var/www/api.appname.com/html/appname.ini
[Install]
WantedBy=multi-user.target
/var/www/api.appname.com/html/wsgi.py
from run import app
if __name__ == "__main__":
app.run()
/var/www/api.appname.com/html/run.py
import os
from src.app import create_app
env_name = os.getenv('FLASK_ENV')
app = create_app(env_name)
if __name__ == '__main__':
port = os.getenv('PORT')
# run app
app.run(host='0.0.0.0', port=port)
/var/www/api.appname.com/html/src/app.py
from flask import Flask
from flask_cors import CORS
from .config import app_config
from .models import db, bcrypt
from .users.users_api import user_api as user_blueprint
from .categories.categories_api import category_api as category_blueprint
from .listings.listings_api import listing_api as listing_blueprint
from .machinelearning.machine_learning_api import machine_learning_api as machine_learning_blueprint
from .payments.payments_api import payment_api as payment_blueprint
def create_app(env_name):
"""
Create app
"""
# App initiliasation and CORS configuration
app = Flask(__name__)
cors = CORS(app, resources={r"/*": {"origins": "*"}})
#app.config.from_object(app_config[env_name])
app.config.from_object(app_config['production'])
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# Initialise Bcrypt and SQLAlchemy
bcrypt.init_app(app)
db.init_app(app)
# Register blueprints
app.register_blueprint(user_blueprint, url_prefix='/v1/resources/users')
app.register_blueprint(category_blueprint, url_prefix='/v1/resources/categories')
app.register_blueprint(listing_blueprint, url_prefix='/v1/resources/listings')
app.register_blueprint(machine_learning_blueprint, url_prefix='/v1/resources/ml')
app.register_blueprint(payment_blueprint, url_prefix='/v1/resources/payments')
# Default API endpoint
@app.route('/', methods=['GET'])
def index():
"""
home endpoint
"""
return 'You are connected to the AppName API!'
return app
/var/www/api.appname.com/html/appname.ini
[uwsgi]
module = wsgi:app
master = true
processes = 2
socket = appname.sock
chmod-socket = 660
vacuum = true
die-on-term = true
/etc/nginx/sites-available/api.appname.com
server {
listen 80;
listen [::]:80;
#root /var/www/api.appname.com/html;
index index.html index.htm index.nginx-debian.html;
server_name api.appname.com;
location / {
# try_files $uri $uri/ =404;
#proxy_pass http://localhost:5000;
#proxy_http_version 1.1;
#proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection 'upgrade';
#proxy_set_header Host $host;
#proxy_cache_bypass $http_upgrade;
include uwsgi_params;
uwsgi_pass unix:/var/www/api.appname.com/html/appname.sock;
}
}
/var/www/api.appname.com/html/appname.sock
的权限为666
。
不确定其他信息会有所帮助...一切似乎运行正常,但出现502网关错误。我还重新启动了Nginx,但没有成功。