Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to combine flask with apache

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to combine flask with apache, which has certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

The development Web server that comes with flask performs poorly, responds slowly, and does reverse proxying directly through nginx, often unable to respond to requests. There are two good-performing servers that support Flask programs that can be used in a production environment, Gunicorn and uWSGI, but these two modules do not provide support for window.

So we need to use the mod_wsgi module to enable flask to be deployed on apache. The mod_wsgi module is an Apache FastCGI module written by python. (recommended study: use of apache)

After the download is finished, extract the Apache24, open it into the conf file, open it with text, and I use Atom to open it here.

Now let's explain what we need to change:

1. ServerRoot "c:/Apache24": modify to your own directory address

2. Listen 8080: Port number configuration. Some users may find that their port 80 is occupied, which may be occupied by IIS or SQLserver. We can modify this port number to facilitate testing.

3. Modify directory authorization

The original:

AllowOverride noneRequire all denied

After modification:

Options FollowSymLinksAllowOverride NoneOrder deny,allowAllow from all

4. Change the document root path to your own file path.

DocumentRoot "c:/Apache24/htdocs"

5. Mod module configuration (key points)

(1) first install the downloaded mod.whl file:

Pip install

(2) after the installation is successful, run the following command:

Mod_wsgi-express module-config

(3) after the above command runs successfully, we can get three messages:

(4) then use these three pieces of information instead of .so file to add to the configuration file of apache:

6. Configure the site (key points):

# definition. These values also provide defaults for# any containers you may define later in the file.

Because I am a person who doesn't know how to configure apache, I don't know where to put the configuration in the reference link at first, so I can find this sentence through full-text search, and I can be sure to put this at the bottom of the file.

Copy the following paragraph to the bottom of the conf file and change the path to your own path

ServerAdmin example@xx.comDocumentRoot E:\ Environment\ Apache\ Apache24\ text_webOrder allow,denyAllow from allWSGIScriptAlias / E:\ Environment\ Apache\ Apache24\ text_web\ test.wsgi

The site configuration instructions above:

(1) Project path (not necessarily under the apache directory):

DocumentRoot E:\ Environment\ Apache\ Apache24\ text_web

(2) wsgi module startup file (key points):

WSGIScriptAlias / E:\ Environment\ Apache\ Apache24\ text_web\ test.wsgi

Note: the "/" here is required, indicating the url prefix, which can be modified later on as needed.

(3) Project path permissions: set to allow all

Order allow,denyAllow from all

At this point, our httpd.conf file has been configured.

2. Enter the configuration of the flask project below:

Project catalog:

1. Test.wsgi file description:

Import syssys.path.insert (0, "E:/Environment/Apache/Apache24/text_web") # Project path

From test import app # introduced our flask project project name

Application = app # applcation must not be changed to anything else, because when wsgin parses this file, it only recognizes applcation (reference link)

2. The master file of flask

From flask import Flask app = Flask (_ _ name__) @ app.route ('/ hello') def hello_world (): return 'Hello Worldwaters' If _ _ name__ = ='_ _ main__': app.run ()

At this point, our project configuration is basically complete, and we need to pay special attention to the introduction of the project in the wsgi file.

Start or install apache

Start cmd in administrator mode and go to the bin file path of Apache24:

Install apache to serve the system:

Httpd-k install

Start apache:

Httpd-k start

I have found that some computers can be run directly by opening httpd.exe without installing httpd into the system service.

Other apache commands that may be used:

Stop the apache service:

Httpd-k stop

Restart the apache service:

Httpd-k restart thank you for reading this article carefully. I hope the editor will share how flask combines apache content to help you. At the same time, I also hope you can support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report