Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
296 views
in Technique[技术] by (71.8m points)

python - How to run Nginx and deploy a Flask application with Nginx and uWSGI?

I am deploying Flask application with Nginx and uWSGI for first time. Nginx will listen to port 8000 and WSGI will listen to 8081. I followed the instructions given in problem statement, but the NGINX fails to start.

This is what I did: wsgi.py

# Put your code here
from projects.challenge import create_app

app = create_app()

deloy.conf

server {
    listen 8000;
    server localhost:8081;

    location /Hello{
      include uwsgi_params;
      uwsgi_pass 127.0.0.1:8081;

    }

    location /static {
        alias /home/deploy/project/static;
    }
}

The test code given in the question for testing deploy.conf is:

def test_conf_file_contents(self):
        with open('deploy.conf', 'r') as f:
            content = f.read()
            assert "location /Hello" in content
            assert "server localhost:8081" in content
            assert "listen 8000" in content

api.py

from flask import Flask, request, make_response


app = Flask(__name__)
app.secret_key = "Thisisyoursecret"


# Create a simple endpoint /Hello with return message "Welcome to your flask application"

@app.route('/Hello')
def hello():
  res=make_response("Welcome to your flask application")
  return res


if __name__=='__main__':
  app.run()

As per instruction in the question, I included deploy.conf in Virtual Host Configs of nginx.conf file as follows:

http{
   ...
        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
        include /projects/challenge/deploy.conf
}

uwsgi.ini

[uwsgi]
socket=127.0.0.1:8081
wsgi-file=wsgi.py

The error is:

user@workspacede6jnv452qg2cr45:/projects/challenge$ sudo service nginx restart
 * Restarting nginx nginx                                                                [fail] 
user@workspacede6jnv452qg2cr45:/projects/challenge$ 

On going to path etc/nginx and starting:

user@workspacede6jnv452qg2cr45:/etc/nginx$ sudo service nginx restart
 * Restarting nginx nginx                                                                 [fail]

Kindly suggest me what to do.

question from:https://stackoverflow.com/questions/65650212/how-to-run-nginx-and-deploy-a-flask-application-with-nginx-and-uwsgi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...