Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 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 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...