我使用PyMysql安装了Flask
当我以开发模式python test.py
运行它时,一切都很好,在浏览器中我能够在端口5000下看到SQL Select的结果
当我运行使用WSGI的Nginx service test start
然后我得到内部服务器错误。我想它不是端口问题而是用户访问问题?我不知道为什么同一个文件在DEV中正常运行但在WSGI下运行不正常。或者可能是在nginx下它无法识别localhost?
app.py
from flask import Flask, request, render_template
import pymysql
db = pymysql.connect("localhost", "root", "123", "test1")
app = Flask(__name__)
#api = api(app)
@app.route('/')
def someName():
cursor = db.cursor()
sql = "SELECT name,password FROM Users"
cursor.execute(sql)
results = cursor.fetchone()
return results[0] + str(results[1])
# return render_template('index.html', results=results)
if __name__ == '__main__':
app.run(host='0.0.0.0')
app.debug = true
nginx配置
server {
listen 80 default_server;
# root /usr/share/nginx/html;
root /var/www/html;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name mywebsite.com;
location / { try_files $uri @rocket; }
location @rocket {
include uwsgi_params;
uwsgi_pass unix:///var/www/rocket/myproject.sock;
}
location /images {
alias /var/www/rocket/im;
index index.html;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:///run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
}
wsgi.py
from rocket import app
if __name__ == "__main__":
app.run()
app.debug = true
app.ini
[uwsgi]
module = wsgi:app
master = true
processes = 5
socket = myproject.sock
chmod-socket = 660
vacuum = true
die-on-term = true
logto = /var/www/rocket/%n.log
error.log中 ---找不到python应用程序,检查启动日志是否有错误