A pyramid configured on a shared host with fastcgi returns the .fcgi file back to the browser

Can someone help me with the procedure of creating a production server on a shared host with a pyramid? I searched all day trying to do this job, but nothing works.

I'm having trouble writing .htaccess and index.fcgi files. I tried to combine these textbooks; 1 , 2 , 3 , 4 to figure this out, but when I visit the website, I see the contents of the index. fcgi instead of application. I have taken the following steps:

  • Created a virtual environment for python in the home directory and activated it:

     mkdir temp; cd temp
     curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-12.0.7.tar.gz
     gzip -cd virtualenv-12.0.7.tar.gz |tar xf -
     cd virtualenv-12.0.7
     python2.7 setup.py install --user
     cd ~
     ~/.local/bin/virtualenv pyramid --python=python2.7
     source ~/pyramid/bin/activate
    
  • Installed pyramid in a virtual environment.

    pip install pyramid
    
  • A test project has been created;

    pcreate -s starter myProject
    cd myProject
    python setup.py install
    
  • Installed thread

    pip install flup
    
  • index.fcgi public_html :

    #!/home3/reyhane/pyramid/bin/python
    import os
    import sys 
    
    myapp = '/home3/reyhane/myProject'
    inifile = 'production.ini'
    sys.path.insert(0, myapp )
    
    from paste.deploy import loadapp
    wsgi_app = loadapp('config:' + myapp + '/' + inifile)
    if __name__ == '__main__':
        from flup.server.fcgi import WSGIServer
        WSGIServer(wsgi_app).run()
    
  • index.fcgi;

    cd public_html
    chmod +x index.fcgi 
    

    - 0755.

  • .htaccess public_html :

    AddHandler fastcgi-script .fcgi
    DirectoryIndex index.fcgi
    
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.fcgi$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.fcgi/$1 [L]
    AddType "text/html; charset=UTF-8" html
    AddType "text/plain; charset=UTF-8" txt 
    AddCharset UTF-8 .html
    AddDefaultCharset UTF-8
    

, :

    home3/reyhane/
    |-- pyramid
    |-- myProject
    |   |-- myProject
    |   |-- production.ini
    |-- public_html/
    |   |-- index.fcgi
    |   |-- .htaccess

, .htaccess , index.fcgi, index.fcgi.

+4
1

htaccess, :

AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ YOUR_APP_NAME.fcgi/$1 [QSA,L]

FCGI:

#$HOME/YOUR_APP_NAME/bin/python
import sys
from paste.deploy
import loadapp
from flup.server.fcgi_fork import WSGIServer
app = loadapp('config:$HOME/YOUR_APP_NAME/src/production.ini')
server = WSGIServer(app)
server.run()

Pyramid " " . , .

+1

Source: https://habr.com/ru/post/1617294/


All Articles