Documentation for Python LiteSpeed Server API https://www.litespeedtech.com/images/logos/litespeed/litespeed-logo.png 2019-09-20 13:40:13 Installing, configuring, and using Python LiteSpeed Server API

Python LSAPI Documentation

Installing, configuring, and using Python LSAPI

Table of Contents

Installation | Administration | Configuration

Python LSAPI Installation

  1. Download the module: Python LSAPI (WSGI LSAPI) can be downloaded here.
  2. Run the following commands to compile the LSWSGI executable: (It has been assumed that wsgi-lsapi-X.X was downloaded to /usr/local/lsws/)
    cd /usr/local/lsws/wsgi-lsapi-1.1
    python ./configure.py
    make
  1. Move the file lswsgi to /usr/local/lsws/fcgi-bin/. This directory is where all your LSAPI executables go.

Python LSAPI Administration

Using Apache Configurations

With the Python LSAPI module, LiteSpeed Web Server can automatically detect and utilize settings for existing Python applications using mod_wsgi. No change should be necessary to bring in an application from Apache.

Using Native LiteSpeed Configurations

Python applications can be set up with LSAPI using the same methods used with any other LSAPI application — by setting up an external application and script handler in the WebAdmin console.

  1. Setting up an external application:

    1. Go to the External App tab (WebAdmin console > Configuration > External App) and add an external application. (This can be done at the server or virtual host level.)
    2. Set Type to "LSAPI App"
    3. Give your external application a name and a socket. Most importantly, for the Command setting, specify the location of the lswsgi executable: "/usr/local/lsws/fcgi-bin/lswsgi". (You also have to pick values for Max Connections, Initial Request Timeout, and Retry Timeout.)
  2. Setting up a script handler:

    A WSGI script handler will tell LSWS to send .wsgi scripts to the LSWSGI application.

    1. Go to the Script Handler tab (WebAdmin console > Configuration > Script Handler) and click Add. (This, also, can be done at the server or virtual host level.)
    2. Set Suffix to ".wsgi" (the suffix of my WSGI Python apps). Set Handler Type to "LiteSpeed SAPI". For Handler Name, choose the LSWSGI external application just created.
  3. Graceful restart to apply changes.

suEXEC

suEXEC is usually preferred in the shared hosting environment. LSWS will start a Python WSGI application in suEXEC mode (running as the same user ID as the site owner) when the PHP suEXEC setting is enabled (WebAdmin console > Configuration > General). It will follow the same security model used for PHP. For each account, the maximum concurrent processes follows the PHP suEXEC Max Conn setting (WebAdmin console > Configuration > General).

The default settings for the Python LSAPI, though, only set up suEXEC for for applications with the suffix .wsgi. If you need Python LSAPI to run scripts with other suffixes in suEXEC, there are two ways to set this up:

  1. For Apache configurations: Create a script handler for the suffix .wsgi, then add the directive AddType application/x-httpd-wsgi .yoursuffix to this script handler.
  2. For native LiteSpeed configurations: Add a comma and your suffix after ".wsgi" in step 2ii above. (Example: ".wsgi, .py") ".wsgi" must be the first suffix in order for this to work.

Python LSAPI Configuration

Using Apache Settings

With the Python module, LSWS will automatically detect and use Apache mod_wsgi settings. The Python LSAPI module is compatible with the following mod_wsgi directives:

WSGIApplicationGroup
WSGICallableObject
WSGIScriptReloading
WSGIScriptAlias
WSGIScriptAliasMatch

Using LiteSpeed Native Settings

External Application Settings

LSAPI external application settings are explained in the LiteSpeed Web Server documentation. You can achieve the results of the Apache directives listed above by using script handlers and contexts in LSWS. These settings are also explained in the LSWS documentation.

Environment Variables

Python LSAPI applications can be further configured using the environment variables listed below:

LSAPI_CHILDREN
(default: 0)

LSAPI allows a variety of setups. Two of these setups, Worker and ProcessGroup can be set using this environment variable. (Note: In previous versions of this documentation, Worker was referred to as "server managed mode" and ProcessGroup referred to as "self managed mode".)

Setting LSAPI_CHILDREN to <=1 puts LSWS in Worker mode. In Worker mode, LiteSpeed Web Server dynamically spawns new Python processes to meet demand and kills finished processes. In this mode, an external application's Instances setting (WebAdmin console > Configuration > External App > your external application) should match the Max Connections setting (WebAdmin console > Configuration > External App > your external application).

Setting LSAPI_CHILDREN to >1 puts LSWS in ProcessGroup mode. In ProcessGroup mode, the web server will start one constantly-running Python parent process, and this process will fork child Python processes (as opposed to spawning new processes) to meet demand. ProcessGroup is generally preferred because all Python processes can then share one memory block for opcode caching. In ProcessGroup mode, Instances should be set to 1, while LSAPI_CHILDREN should be set to match the value of Max Connections. Usually, there is no need to set LSAPI_CHILDREN over 100.

LSAPI_AVOID_FORK
(default: 0)

LSAPI_AVOID_FORK specifies whether the internal process manager in ProcessGroup mode should try to avoid forking new child processes. A value can be used to set free memory limit in addition to 0 and 1, the minimum is 10M, default is 1G.

When set to 0, the internal process manager will not try to avoid forking new processes. To save system resources, it will stop processes when they finish and only start child processes when they are needed. This is often preferred in shared hosting.

When set to 1, the internal process manager will try to avoid frequently stopping and starting child processes. This might be preferred in a dedicated hosting environment because it may be faster to recycle existing processes, even if it means running processes when they are unused sometimes.

LSAPI_EXTRA_CHILDREN
(default: 1/3 of LSAPI_CHILDREN or 0)

In ProcessGroup mode, LSAPI_EXTRA_CHILDREN controls the maximum number of extra child processes that can be started when existing child processes are malfunctioning. The total number of child processes will be reduced to the level set in LSAPI_CHILDREN as soon as service is back to normal. When LSAPI_AVOID_FORK is set to 0, the default value of LSAPI_EXTRA_CHILDREN is 1/3 of LSAPI_CHIDLREN. When LSAPI_AVOID_FORK is set to 1, the default value is 0.

LSAPI_MAX_REQS
(default: 10000)

In ProcessGroup mode, this controls how many requests each child process will handle before it exits automatically. This parameter can help reduce memory usage by leaky Python functions.

LSAPI_MAX_IDLE
(default: 300 seconds)

In ProcessGroup mode, LSAPI_MAX_IDLE controls how long an idle child process will wait for a new request before it exits. This option helps release system resources taken by idle processes.

LSAPI_MAX_IDLE_CHILDREN
(default: 1/3 of LSAPI_CHILDREN or LSAPI_CHILDREN)

In ProcessGroup mode, LSAPI_MAX_IDLE_CHILDREN controls how many idle child processes are allowed. Extra idle child processes will be killed by the parent process immediately. When LSAPI_AVOID_FORK is set to 0, the default value of LSAPI_MAX_IDLE_CHILDREN is 1/3 of LSAPI_CHIDLREN. When LSAPI_AVOID_FORK is set to 1, the default value of LSAPI_MAX_IDLE_CHILDREN is the same as the value of LSAPI_CHILDREN.

LSAPI_MAX_PROCESS_TIME
(default: 3600 seconds)

In ProcessGroup mode, LSAPI_MAX_PROCESS_TIME controls the maximum processing time allowed when processing a request. If a child process can not finish processing a request in the given time period, it will be killed by the parent process. This option can help get rid of dead or runaway child processes.

LSAPI_PGRP_MAX_IDLE
(default: FOREVER )

In ProcessGroup mode, LSAPI_PGRP_MAX_IDLE controls how long the parent process will wait before exiting when there are no child processes. This option can help release system resources taken up by an idle parent process. This environment variable has the same function as the Max Idle Time setting (WebAdmin console > Configuration > External App).

LSAPI_PPID_NO_CHECK

By default, an LSAPI external application will exit automatically if the parent process dies. This is to reduce orphan processes when the web server is restarted. However, it may be desirable to disable this feature in situations such as when an LSAPI process was started manually from the command line. Adding the LSAPI_PPID_NO_CHECK environment variable (set it to 1) will disable the checking for the existence of a parent process. To turn off this setting, remove the environment variable completely.

LSAPI_ALLOW_CORE_DUMP

By default, an LSAPI application will not leave a core dump file when it crashes. If you want to have LSAPI dump a core file, you should add this environment variable and set to 1. If set, core files will be created under the current working directory, generally the directory of the Python script that crashed. To turn off this setting, remove the environment variable completely.

Privacy Policy

Privacy Policy

LiteSpeed Technologies, Inc. (aka “LiteSpeed”) is committed to protecting your privacy. This policy ("Privacy Policy" or "Policy") explains our practices for our site, www.litespeedtech.com ("Site"). You can visit most pages of the Site without giving us any information about yourself, but sometimes we do need information to provide services that you request. By using this Site or any products or services provided through the Site, you expressly consent to the use and disclosure of information as described in this Privacy Policy.

LiteSpeed reserves the right to revise, modify, add, or remove provisions to this Privacy Policy at any time. If we make changes to this Privacy Policy, we will update the Effective Date to note the date of such changes. LiteSpeed encourages you to review this Privacy Policy periodically for any changes. IF YOU DO NOT AGREE WITH ANY OF THE TERMS BELOW, YOU SHOULD NOT USE THIS SITE OR THE PRODUCTS OR SERVICES OFFERED BY LITESPEED TECHNOLOGIES AT THIS SITE.

Collection of Information

Personal Information.

LiteSpeed will ask you for certain “Personal Information” when you complete registration or product information request forms on the Site, including but not limited to your name, address, telephone number, email address, and credit card information. You can always choose not to provide us with the requested information, however, you may not be able to complete the transaction or use our products or services if you do not provide the information requested.

Non-Personal Information.

LiteSpeed may collect non-personally identifiable information from you such as the type of browser you use, your operating system, the screen resolution of your browser, your ISP, your IP address, which pages you view on the Site and the time and duration of your visits to the Site (collectively, “Non-Personal Information”). LiteSpeed may associate Non-Personal Information with Personal Information if you register with the Site.

User Communications.

If you communicate with us, we may collect information relating to that communication whether it takes the form of email, fax, letter, forum posting, blog comments, testimonials or any other form of communication between you and LiteSpeed or Submitted by you to the Site (collectively, “User Communications”).

Server Information.

If you use one of our software products such as LiteSpeed Web Server or LiteSpeed Web ADC, we may collect certain information concerning such software and concerning the server upon which the software operates. This information includes: (a) the licensed or unlicensed status of the software; (b) the source from which the license for the software was obtained (i.e., LiteSpeed or a LiteSpeed affiliate); or (c) information about the server upon which the software is installed including (i) the public IP address, (ii) the operating system and (iii) the use of any virtualization technologies on such server ((a) through (c) collectively, “Server Information”). Additionally, “Server Information” may also include information collected from you by LiteSpeed in the event that you request technical support services including without limitation, IP addresses, usernames, and passwords necessary to login to SSH, the root directory of the server upon which you installed the LiteSpeed software and any affected accounts including email accounts, control panel accounts, MySQL accounts, CMS accounts and other accounts.

Use and Storage of Collected Information

LiteSpeed may use Personal Information to create and authenticate your account, to respond to your requests, to provide you with customer and technical support, or to provide you with information regarding our products, services, partners, and company. You may update your Personal Information with us at any time, but we may maintain records of any Personal Information you disclose to us indefinitely, unless otherwise requested as outlined below.

We may use User Communications in the same ways we use Personal Information. If you communicate with us for a particular purpose, we may use your User Communications for that purpose. For example, if you contact us for technical support, we may use your communications to provide technical support to you. We may maintain records of User Communications you transmit to us indefinitely, unless otherwise requested as outlined below.

LiteSpeed may use Non-Personal Information to maintain, evaluate, improve and provide our Site, the Services and any other LiteSpeed products and services. We may retain Non-Personal Information indefinitely.

We may use Server Information to provide you with technical support services and to maintain, evaluate, improve and provide LiteSpeed products and services. We may also use such information to investigate unlicensed (and therefore unauthorized) uses of our software. LiteSpeed may maintain Server Information indefinitely, with the exception of usernames, passwords, and other login information given in connection with support service requests. Such login information will be purged when the ticket is closed.

Disclosure of Collected Information

LiteSpeed will only disclose Personal Information to third parties if acting under a good faith belief that such action is necessary, including but not limited to: (a) to resolve disputes, investigate problems, or comply with laws or regulations; (b) to enforce our Terms of Service; (c) to protect and defend the rights, property, or safety of our company or our users; or (d) in the event of a merger, acquisition or sale of all or substantially all LiteSpeed assets. Other than this limited activity, we do not share, sell, or rent any personal information to third parties.

You will receive notice in the form of modifications to this Policy when information about you might go to third parties other than as described in this Policy, and you always have the opportunity to contact us as set forth below if you do not wish your information to go to third parties.

LiteSpeed cannot be responsible for protecting your information if you share such information in publicly available sections of the Site such as the user forums, blog comments, or testimonials section. You should use your own judgment in disclosing this information on the Site.

Use of Cookies

“Cookies” are small pieces of information that your browser stores on your computer on behalf of a website that you have visited. Cookies may be used in order to complete transactions on our site. You can always choose not to accept cookies with the settings of your web browser, however, you may not be able to complete these transactions if you do not accept cookies.

Security of Personal Information

We use reasonable security methods to protect your personal information from unauthorized access, use or disclosure. No data transmission over the Internet or any wireless network can be guaranteed to be perfectly secure. While we try to protect your personal information, we cannot guarantee the security of any information you transmit to us, and you do so at your own risk.

LiteSpeed uses industry-standard SSL-encryption to protect sensitive data.

In the event that LiteSpeed becomes aware of a security breach, unauthorized disclosure or inadvertent disclosure concerning your information, you agree that LiteSpeed may notify you of such an event using the Personal Information previously provided.

You are responsible for maintaining your account’s security.

GDPR Notice and your Rights as Data Subject

For the purposes of the General Data Protection Regulation (the “GDPR”), in the European Union, LiteSpeed Technologies Inc. is a “data controller” of the Personal Information you provide to us for the primary purposes of providing you or your customers with our services.

For our customers and users in the European Union, by clicking the "I Accept" button or otherwise accepting the terms and conditions of our services through a clickable action or similar action, you hereby acknowledge, agree and unequivocally consent to the collection, processing, management, treatment, transfer and authorization of your Personal Information by LiteSpeed Technologies and/or its affiliates, clients, sub-processors and/or authorized third parties.

If you are a resident of Switzerland, the contact details for the data protection authorities are available here:
https://www.edoeb.admin.ch/edoeb/en/home.html.

For European Union (EU) customers, please be reminded that the EU has not found the United States and some other countries to have an adequate level of protection of Personal Information under Article 45 of the GDPR.

The sections here below cover certain situations that you, as data subject, and we as a data controller, are most likely to encounter; but you should also carefully review the full list of data subject rights here: https://www.gdpr-info.eu/chapter-3/.

  • Right to be Forgotten: You can request us to be “forgotten”; that is, to have your entire Personal Information removed from our service. If we are asked to do this, in accordance with Article 17 GDPR we will remove any Personal Information that we have collected from you as requester. We will also need to contact any third parties that process your Personal Information on our behalf, such as our cloud service providers using the adequate mechanisms. To ensure that any personal data in LiteSpeed Technologies’ possession can be removed in a timely manner, you can relay any request to be “forgotten” to us by submitting a request.
  • Right to Data Portability: In accordance with Article 20 GDPR our users located in the EU may request LiteSpeed Technologies to send them any Personal Information in our possession. In this case, we will provide you with any Personal Information that you have in a commonly used, machine-readable format.
  • Right to Data Access: As a data subject, in accordance with Article 15 GDPR you can ask LiteSpeed Technologies to confirm how and where your Personal Information is being stored and processed. You also have the right to know how such data is shared with third parties by us.
  • Right to Data Rectification: As a data subject, in accordance with Article 16 GDPR you have the right to obtain from LiteSpeed Technologies, without undue delay, the rectification of inaccurate Personal Information concerning you.
  • Right to be Informed: You have the right to be informed about the Personal Information we collect from you, and how we process it.
  • Right to Withdraw Consent: In accordance with Article 7(3) GDPR, you have the right to withdraw your consent given to us at any time.
  • Right to Object: In accordance with Article 18 GDPR you have the right to object to us processing your Personal Information for the following reasons:
    • Processing was not based on legitimate interests or the performance of a task in the public interest/exercise of official authority (including profiling);
    • Direct marketing (including profiling);
    • Processing for purposes of scientific/historical research and statistics; and
    • Rights in relation to automated decision-making and profiling.
  • Automated Individual Decision-Making and Profiling: You have the right not to be subject to a decision based solely on automated processing, including profiling, which produces legal effects concerning you or similarly significantly affects you.
  • Right to Complain: You have the right to file a complaint with supervisory authorities if your information has not been processed in compliance with the GDPR. Furthermore, in accordance with Article 77 GDPR, if the supervisory authorities fail to address your complaint properly, you may have the right to a judicial remedy.

Privacy Requests

Lastly, you retain the right to access, amend, correct or delete your Personal Information where it is inaccurate at any time. To do so, please contact us as indicated in the Contact Us section. We reserve the right to charge a reasonable fee, as permitted by applicable laws and regulations, in order to comply with complex requests or repetitive requests from individual users.

Your privacy request must include, at the least, the following information: (i) your complete name, address and/or e-mail address in order for us to notify you of the response to your request; (ii) attached documents establishing your identity; and (iii) a clear and concise description of the Personal Information with regard to which you seek to enforce any of your privacy rights. If you request rectification, please indicate amendments to be made and attach documentation to back up your request.

Upon receipt of your privacy request, and after due review, we may then edit, deactivate and/or delete your Personal Information from our services for the maximum term allowed by the GDPR for each applicable case. In case of secure databases under our control where deletion is impossible, we will make such information permanently inaccessible.

Notice to California Residents

Pursuant to the California Consumer Privacy Act of 2018 (the “CCPA”), LiteSpeed Technologies and/or its affiliates, clients, sub-processors and/or authorized third parties hereto provide the following Privacy Policy notice regarding the categories of Personal Information that we may collect and/or disclose within the preceding twelve (12) months regarding California residents who are not employees, independent contractors, owners, directors, officers, or job applicants of LiteSpeed Technologies, or emergency contacts or benefits beneficiaries of the foregoing.

Thenceforth, the CCPA provides Californians with the following rights:

  • Requests for Information: you (or your authorized agent) can request a copy of your Personal Information, including how we have collected, used, and shared your Personal Information over the past 12 months (if any), including the categories of Personal Information we collected and our purposes for doing so; the categories of sources for that information; the categories of third parties with whom we shared it for a business purpose and our purposes for doing so.
  • Your Right to Notification: under the CCPA, we cannot collect new categories of Personal Information or use them for materially different purposes without first notifying you.
  • Nondiscrimination for exercising your CCPA Rights: the CCPA prohibits us from discriminating against you for exercising your rights under the law. Such discrimination may include denying services, charging different prices or rates for services, providing a different level or quality of services, or suggesting that you will receive a different level or quality of goods or services as a result of exercising your rights.
  • Your Right to Delete Personal Information: you can request that we delete your Personal Information by contacting us. You also can request that we delete specific information, and we will honor such requests, unless a due exception applies, such as when the information is necessary to complete a transaction, verify a fraud, review a chargeback or contract for which it was collected or when it is being used to detect, prevent, or investigate security incidents, comply with laws, identify and repair bugs or ensure another consumer’s ability to exercise their free speech rights or other rights provided by law.
    • Please take into consideration that we may deny your deletion request if retaining the Personal Information is necessary for us, our affiliates or our service providers in order to:

      • Complete the transaction for which we collected the Personal Information, provide a good or service that you requested, take actions reasonably anticipated within the context of our ongoing business relationship with you, or otherwise perform our contract with you;
      • Detect security incidents, protect against malicious, deceptive, fraudulent, or illegal activity, or prosecute those responsible for such activities;
      • Debug our products to identify and repair errors that impair existing intended functionality;
      • Exercise free speech, ensure the right of another consumer to exercise their free speech rights, or exercise another right provided for by law;
      • Comply with the California Electronic Communications Privacy Act (Cal. Penal Code § 1546 seq.);
      • Enable solely internal uses that are reasonably aligned with consumer expectations based on your relationship with us;
      • Comply with a legal obligation that has substantive grounds;
      • Make other internal and lawful uses of that information that are compatible with the context in which you provided it.

Overall, we have, may or will collect the following categories of Personal Information from our users, customers and individuals, as necessary to fulfill our legal obligations and operational business purposes:

  • Personal information (as defined in the California Customer Records Law), such as contact information;
  • Identifiers, such as online identifier, IP address and name;
  • Internet or network activity information, such as browsing history and interactions with our and other websites and systems;
  • Geo-localization data, such as device location and IP location;
  • Audio, electronic, visual and similar information, such as video recordings and multimedia content created in connection with our business activities; and
  • Inferences drawn from any of the Personal Information listed above to create a profile or summary about, for example, an individual’s preferences and characteristics.

International Data Transfer Notice

LiteSpeed Technologies values your users’ privacy. Although our software does not directly collect any personally identifiable information from visitors to your site, LiteSpeed may still be considered a data processor in certain jurisdictions, as user information may be temporarily cached and/or logged, as outlined in this document.

We have our headquarters in the State of Pennsylvania, United States of America (USA). Henceforth, your Personal Information may be accessed by us or our affiliates, agents, partners and third-party service providers in the USA and our locations which may or may not be located in your country of residence, and you hereby consent to such access and transfer by simple disclosure.

Servers

LiteSpeed Web Server, OpenLiteSpeed, LiteSpeed Web ADC, and related software may record IP addresses as a part of normal logging. An access log and an error log may record visitor IP addresses and URL visited. The logs are stored locally on the system where LiteSpeed server software is installed and are not transferred to or accessed by LiteSpeed employees in any way, except as necessary in providing routine technical support if you request it. This logging may be turned off through configuration. It is up to individual server administrators to come up with their own schedule for removing such logs from the file system.

Cache Solutions

Our cache plugins potentially store a duplicate copy of every web page on display on your site. The pages are stored locally on the system where LiteSpeed server software is installed and are not transferred to or accessed by LiteSpeed employees in any way, except as necessary in providing routine technical support if you request it. All cache files are temporary, and may easily be purged before their natural expiration, if necessary, via a Purge All command. It is up to individual site administrators to come up with their own cache expiration rules.

LSCache for WordPress

In addition to caching, our WordPress plugin has an Image Optimization feature. When optimization is requested, images are transmitted to a remote LiteSpeed server, processed, and then transmitted back for use on your site. LiteSpeed keeps copies of optimized images for 7 days (in case of network stability issues) and then permanently deletes them.

Similarly, the WordPress plugin has a Reporting feature whereby a site owner can transmit an environment report to our server so that we may better provide technical support.

Neither of these features collects any visitor data. Only server and site data is involved.

Support Services

Sometimes, when you request technical support, LiteSpeed may ask for login credentials to various areas of your site. You may refuse to share such credentials, however refusal may impact LiteSpeed’s ability to provide the requested support services.

Upon completion of a support ticket, LiteSpeed immediately deletes all login credentials you may have shared.

Any user data encountered by LiteSpeed is kept strictly confidential. We never provide your support ticket information to any third party without your explicit consent.

Contact Us

If you would like to update information that you have voluntarily provided to us, stop receiving information from us, or exercise any of the rights granted to you under Privacy Laws, including the EU’s General Data Protection Regulation, please e-mail info@litespeedtech.com.