Documents Product Categories OpenLiteSpeed Django

OpenLiteSpeed Django

Jun 28, 2024
Virtual Hosts > Context > Add: Type = App Server URI = / Location = /usr/local/lsws/Example/html/demo/ Binary Path = /usr/local/lsws/fcgi-bin/lswsgi Application Type = WSGI Startup File = demo/wsgi.py Environment = PYTHONHOME=/usr/local/lsws/Example/html /Benchmark Comparison Use the following command to test from an x-CPU plan server(ab) to an x-CPU plan server(DOMAIN) ab -n 100000 -k -H "Accept-Encoding: gzip,deflate" -c 100 http://DOMAIN/ Requests per Second (The larger the number, the better) Nginx+Gunicorn Openlitespeed 700 1750 How to Access the Installed Software From a terminal on your local computer, connect to the server as root, like so: ssh root@use_your_server_ip Be sure to substitute the server’s public IP address for use_your_server_ip . Web Server Control Panel Access Get the WebAdmin admin password: cat .litespeed_password Visit https://use_your_server_ip:7080 to access WebAdmin in a browser. /By default, WebAdmin uses port 7080. To allow access to 7080 from your IP(e.g. 1.2.3.4): ufw allow from 1.2.3.4 to any port 7080 You can also allow all IPs access to port 7080: ufw allow 7080 We suggest turning this port off once you''ve nished setup: ufw delete allow 7080 Django Administration Page /Run the following command in the project directory to setup an account and password: python3 manage.py createsuperuser Optional Setup Enable HTTPS Setting up an SSL certicate enables HTTPS on the web server, which secures the trafc between the server and the clients connecting to it. Certbot is a free and automated way to set up SSL certicates on a server. Step 1. Register Domain To use Certbot, you’ll need a registered domain name and DNS records: An A record from the domain (e.g., example.com ) to the server’s IP address An A record from the domain prefaced with www (e.g., www.example.com ) to the server’s IP address. Step 2. Add Domain to Listener Navigate to OpenLiteSpeed Web Server WebAdmin > Listeners, and add Your Domain to HTTP/HTTPS. /Step 3. Certbot Once the DNS records are set up, you can generate the SSL certicate. Be sure to substitute the correct domain name in the following command: certbot certonly --webroot -w /var/www/html/ -d example.com -d www.exampl If certicate verication is a success, you should nd your certicate les stored in /etc/letsencrypt/ Step 4. Set SSL for HTTPS Navigate to OpenLiteSpeed Web Server WebAdmin > Listeners > SSL, and edit the following three items: Private Key File = /etc/letsencrypt/live/example.com/privkey.pem Certicate File = /etc/letsencrypt/live/example.com/fullchain.pem Chained Certicate = Yes Save and perform a Graceful Restart. Now your server should support TLS1.1, TLS 1.2, and TLS 1.3. Step 5. Redirect HTTP to HTTPS /HTTPS trafc on port 443 is already allowed through the rewall. After you set up HTTPS, you can optionally rewrite all HTTP trafc to HTTPS. Add the following rules to OpenLiteSpeed Web Server WebAdmin > Virtual Hosts > Rewrite > Rewrite Rules RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://example.com/$1 [R,L] Method for Uploading Files You can serve les from the web server by adding them to the web root using SFTP or other tools. Frequently Asked Questions How do I Reset my Web Server WebAdmin Password? If you forget your password, you may run the following command to reset it: /usr/local/lsws/admin/misc/admpass.sh It will ask for the WebAdmin username, which should be admin . Then, enter your new password. How do I Create Additional Virtual Hosts? Manual Setup By default, OpenLiteSpeed has an example virtual host already created. You can create more virtual hosts if you like. See Create Virtual Hosts on OpenLiteSpeed. /How do I Create Additional Apps by Context? How do I Change the Django Startup File? If you want to change the default startup le name from wsgi.py to demo.js , just update the Context and set Startup File = demo.py . How do I Create Django with a Virtual Environment? How do I Fix Permission Issues? chown -R nobody:nogroup /usr/local/lsws/Example/html/demo Change /usr/local/lsws/Example/demo to your actual project path How do I Switch SQLite to PostgreSQL? If you would prefer to use PostgreSQL instead of the default SQLite 3 database, try the following steps: 1. Install PostgreSQL: apt install postgresql postgresql-contrib -y 2. Create the database, user, and password, and apply privileges: sudo -u postgres psql CREATE DATABASE demo; CREATE USER myprojectuser WITH PASSWORD ''password''; GRANT ALL PRIVILEGES ON DATABASE demo TO myprojectuser; \q 3. Access the virtual environment by following step 3: source /usr/local/lsws/Example/html/bin/activate 4. Install PostgreSQL drivers for Python 3: pip3 install psycopg2-binary /5. Update the Django project database. Go to the project, and edit the settings.py le: cd /usr/local/lsws/Example/html/demo vi demo/settings.py Update database section, replacing the following: DATABASES = { ''default'': { ''ENGINE'': ''django.db.backends.sqlite3'', ''NAME'': os.path.join(BASE_DIR, ''db.sqlite3''), } } with: DATABASES = { ''default'': { ''ENGINE'': ''django.db.backends.postgresql_psycopg2'', ''NAME'': ''demo'', ''USER'': ''myprojectuser'', ''PASSWORD'': ''password'', ''HOST'': ''localhost'', ''PORT'': '''', } } 6. Update/migrate the database: python3 manage.py makemigrations python3 manage.py migrate Verify the database connection with the following command: python3 manage.py shell >>> from django import db >>> print(db.connections.databases) /Output: {''default'': {''ENGINE'': ''django.db.backends.postgresql_psycopg2'', ''NAME'': If you have existing data that must be migrated, take a look at this StackOverow topic for tips. Note: Feel free to use the database name, username and password of your choice. How do I Set Up a Wagtail Project with an Existing Cong? Move default "Hello World" demo site from server: mv /usr/local/lsws/Example/html/demo /tmp Install Wagtail python package: pip3 install wagtail Start a new demo site: wagtail start demo Access the project directory: cd demo Install the required package: pip3 install -r requirements.txt python3 manage.py migrate Create a static le folder: mkdir -p /usr/local/lsws/Example/html/demo/demo/public/static /Add these two lines to the end of /usr/local/lsws/Example/html/demo/demo/settings/base.py : STATIC_URL = ''/python/static/'' STATIC_ROOT = ''/usr/local/lsws/Example/html/demo/public/static'' Collect static les: python3 manage.py collectstatic Create superuser for admin page access: python3 manage.py createsuperuser Change owner to default LiteSpeed permissions: chown -R nobody:nogroup /usr/local/lsws/Example/html/demo/ Front page: Admin page: /How do I Import my Django Project From Git? Let''s use pyconbalkan as an example. To import the project, run the following command: git clone https://github.com/PythonBalkan/pyconbalkan Install your project''s requirements: pip3 install -r requirements.txt Create a .env le, and the content required by the project. Run migrate: python3 manage.py migrate Follow the Set Up Demo Django Project instructions to set up settings.py , collect static les, and change owner and context. More info You should see the following screen: //">
To view the full page, please visit: OpenLiteSpeed Django Product Userguide

OpenLiteSpeed Django

Ready to use in production
Buy now