This is a method of hosting the backend processing of the web application in Python using the subdomain added to the original domain by Xserver. I think that the method of hosting in the cloud such as GCP and AWS is common these days, but this time I will do it with Xserver in consideration of cost and performance.
There are already a number of excellent articles about the details, and even if you describe it, it will be a deteriorated copy, so I will omit it, but since there was no particular part about creating an API with a subdomain, I will focus on the flow here. I will describe it. It's like my own memo, so I don't know.
It is assumed that the Xserver's own domain already exists.
(In my case) already https://np-sys.com/ Add a subdomain to https://APIs.np-sys.com/ Folder name to store API / Slug of URL defined in Flask (end) Let's run the backend processing in the form of. Of course, you can use your favorite domain.
Python that I put in the Xserver Python Flask library
--Install python on Xserver --Create a subdomain on the server panel of Xserver, and create a folder name to store the API in public_html. For example, create a folder called functions --Run python scripts with cgi
is.
I have Python originally included in the Xserver, but due to permissions I can't install any libraries with the pip command. Therefore, you need to include your own Python. The following was easy to understand for the detailed method. This is quite a burden. https://note.com/coeeff/n/neab8acfde97e https://qiita.com/kusumoto-t/items/b262b8878ccdfd137fa3
Create a subdomain in the server panel of the Xserver. https://www.xserver.ne.jp/login_server.php
You can go with the touch of a button.
Then connect to the top of that subdomain by FTP or ssh and create a folder to put the script. This time I chose functions. Please do not think that the characters of the subdomain are not in consideration of security because they do not describe the actual ones.
After that, let's run python with cgi. This was the easiest to understand. https://neko-py.com/xserver-web-application
Note that don't forget to change the permissions and specify the Python path as an absolute path at the beginning of index.cgi (#! /home/Myname/.linuxbrew/bin/python3 worked, but #! It didn't work with ~ / .linuxbrew / bin / python3), but be careful about installing Flask properly.
Then https://apis.np-sys.com/functions/ It works with the URL corresponding to.
It seems easier to understand if you manage the folder name created at the top of the subdomain for each application.
Recommended Posts