I have developed a python flask application and I’m trying to publish it on Linux Server as WebService. It doesn’t have any interface it just return string or something like this. I have developed it on Windows and my code was like in the below:
if __name__ == '__main__':
app.run(port=80, debug=True)
Then I have connected to linux server via SSH.
I installed my codes to -> /var/www/myapp/code
Then I created a myapp.conf config file to -> /etc/nginx/sites-enabled:
server {
listen 127.0.0.1:80;
server_name x.x.x.x;
root /var/www/myapp/code/main.py;
passenger_enabled on;
}
Then I run "python main.py" in /var/www/myapp/code/ Then I get:
return getattr(self._sock,name)(args)
socket.error: [Errno 98] Address already in use
When I change listen 127.0.0.1:80; to 80 it works but i can’t send any request. I’m trying to send via postman as http ://x.x.x.x:80/myurl
How can I publish it correctly? I want to serve it on Linux Server and send request from my windows post man application.
Thanks.
3
Answers
use :
for change your ip
You are trying to use same port for your flask app and nginx
Use a different port for flask app
Also, nginx can’t talk to python apps directly, instead you have to proxy the requests to flask server
Adding on @Conans-Answer
Request you to refer the Documentation:- https://flask.palletsprojects.com/en/1.1.x/deploying/wsgi-standalone/