How to remove /cgi-bin/app.wsgi/ from the end of my website URL

22 Views Asked by At

This is the first time I publish a Flask website on an Apache shared host, following the steps https://medium.com/@sergioyahni/deploy-a-flask-app-on-apache-shared-hosting-with-mysql-4dc5340611b7 and adapting.

But my site had a strange URL, the home page normally works www.my-site.com, but the rest of the routes were: www.my-site.com/cgi-bin/app.wsgi/page www.my-site.com/cgi-bin/app.wsgi/login

I've done a lot of research so far, but I couldn't even understand many of the solutions, I'm inexperienced in Apache servers and Hostgator support seems to know even less.

The site works normally, but the URL looks like this, I'll go through the settings I made:

.htacess

Options +ExecCGI
AddHandler cgi-script .wsgi
RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /cgi-bin/app.wsgi [L]

/cgi-bin/app.wsgi

#!/usr/bin/python3
from wsgiref.handlers import CGIHandler

from sys import path
path.insert(0, '/home1/emp23242/public_html/cgi-bin/venv/lib/python3.6/site-packages')
path.insert(0, '/home1/emp23242/public_html/cgi-bin/')
from app import app as application


CGIHandler().run(application)

/cgi-bin/app.py

import os
import sys
sys.path.insert(0, 
'/home1/emp23242/public_html/cgi-bin/venv/lib/python3.6/site-packages')

from my-site import app

if __name__ == '__main__':
    app.debug = False
    app.run(host='0.0.0.0', port=8000)

The closest I got was adding this to app.wsgi:

class ProxyFix(object):
   def __init__(self, app):
       self.app = app

   def __call__(self, environ, start_response):
       environ['SERVER_NAME'] = "empresabrasilturismo.com.br"
       environ['SERVER_PORT'] = "80"
       environ['REQUEST_METHOD'] = "GET"
       environ['SCRIPT_NAME'] = ""
       environ['QUERY_STRING'] = ""
       environ['SERVER_PROTOCOL'] = "HTTP/1.1"
       return self.app(environ, start_response)

if __name__ == '__main__':
    app.wsgi_app = ProxyFix(app.wsgi_app)
    CGIHandler().run(app)

But only GET requests work, and POST gave an error.

0

There are 0 best solutions below