Code Monkey home page Code Monkey logo

webproject's Introduction

webproject

This is a basic web app to illustrate deployment on Microsoft IIS, Apache + mod_wsgi, or nginx

Table of Contents

Microsoft IIS

Steps

  1. Install IIS on your VM or machine, and enable CGI

  2. Copy webproject to C:/inetpub/wwwroot/webproject

  3. Install Python 3.7 in C:/Python37, and install the necessary libraries django, openpyxl, wfastcgi; see webproject/install_requirements.bat

  4. Navigate to C:/, right-click on Python37, and edit Properties. Under Security, add IIS AppPool\DefaultAppPool. DefaultAppPool is the default app pool.

  5. Enable wfastcgi

    • Open a CMD terminal as Administrator, and run the command wfastcgi-enable.

    • Copy the Python path, and replace the scriptProcessor="<to be filled in>" in web-config-template with the Python path returned by wfastcgi-enable.

  6. Edit the remaining settings in web-config-template then save it as web.config in the C:/inetpub/wwwroot/ directory. It should NOT sit inside webproject/. Other settings can be modified if webproject does NOT sit at C:/inetpub/wwwroot/

    • Edit project PYTHONPATH (path to your project)

    • Edit WSGI_HANDLER (located in your wsgi.py)

    • Edit DJANGO_SETTINGS_MODULE (your settings.py module)

  7. Open Internet Information Services (IIS) Manager. Under connections select the server, then in the center pane under Management select Configuration Editor. Under Section select system.webServer/handlers. Under Section select Unlock Section. This is required because the C:/inetpub/wwwroot/web.config creates a route handler for our project.

  8. Add Virtual Directory. In order to enable serving static files map a static alias to the static directory, C:/inetpub/wwwroot/webproject/static/

  9. Refresh the server and navigate to localhost

Apache and mod_wsgi

References:

For Apache 2.4 and mod_wsgi use the httpd.conf.template

Steps

  1. Download and install Apache 2.4 in C:/Apache24. Use Apache Lounge, or any flavor you prefer.

    • After copying files over to C:/Apache24, open a CMD terminal as Administrator. Navigate to C:/Apache24 and run bin\httpd.exe -k install to install the Apache service. You can then navigate to localhost to view the test page.

    • You can start the service by running httpd.exe -k start

    • You can stop the services by running httpd.exe -k stop and restart it by httpd.exe -k restart

  2. Install Microsoft C++ Build Tools. You will need this before you run pip install mod_wsgi.

  3. Install Python 3.7 in C:/Python37 (you don't need to create a virtual environment)

  4. Install django, openpyxl, modwsgi (see install_requirements.bat)

  5. On a CMD terminal, run mod_wsgi-express module-config, then copy the contents and edit webproject/httpd.conf.template. Edit paths to Python and your Django project.

  6. On a CMD terminal, run C:/Apache24/bin/httpd.exe -k start, open a web browser and navigate to localhost (make sure ALLOWED_HOSTS has been updated).

References:

For Microsoft IIS please use the webproject/web-config-template and the webproject/static/web.config files. Update the web-config-template as needed. It will be used to create a web.config that sits on C:/inetpub/wwwroot/web.config; The directory will contain all project files: C:/inetpub/wwwroot/web.config along with C:/inetpub/wwwroot/webproject.

nginx and Waitress

Steps

  1. Download and copy nginx to C:/.

  2. Install Python 3.7 in C:/Python37 and install

  3. Edit ALLOWED_HOSTS in settings.py. Waitress will be running the Django server at http://localhost:8080.

  4. Collect static files by running python manage.py collectstatic

  5. Edit nginx_waitress/webproeject_nginx.conf

    • Edit the server_name

    • Edit the path to /static (and /media if needed)

    • Edit proxy_pass to match the server running from Waitress (i.e. runserver.py). This will usually be localhost or your IP address

  6. Create two directories inside of C:/nginx/

    • Create sites-enabled and sites-available

    • Copy webproject_nginx.conf to the two directories

  7. Edit C:/nginx/conf/nginx.conf

    • Add include <path to your sites-enabled/webproject_nginx.conf>;

    • Change port 80 to a non-essential port like 10. We will need to utilize 80 for our Django project

  8. Open a terminal at C:/nginx/ and run nginx.exe -t to check files, and if everything is successful run nginx.exe to start the server

  9. Open a web browser and navigate to http://localhost

webproject's People

Contributors

johnnyboycurtis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

webproject's Issues

CSRF verification failed. Request aborted.

I used waitress with nginx everything works okay, but when I login to the app i got error CSRF verification failed. Request aborted.

site available configurations

# mysite_nginx.conf

server {
    # the port your site will be served on
    listen      82;
    server_name 172.30.1.196;
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste
	
	location = /favicon.ico {
		alias C:/Apache24/htdocs/fuel/assets/favicon.ico;
		expires 7d; 
	}
	
	location = robots.txt {
		alias C:/Apache24/htdocs/fuel/frontend/templates/frontend/robortx.txt;
		expires 7d;
	}
    # Django media
    location /media  {
        alias C:/Apache24/htdocs/fuel/media;  # your Django project's media files - amend as required
    }
    # Django static
    location /static {
        alias C:/Apache24/htdocs/fuel/assets; # your Django project's static files - amend as required
        expires 7d; 
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        proxy_pass http://127.0.0.1:92; # See output from runserver.py
		proxy_set_header Host $host; # send host header to django
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # send client ip to django
        proxy_set_header X-Forwarded-Proto $scheme; # send protocal to django
        #proxy_redirect http://127.0.0.1:91
		
    }
}

502 Bad gateway

I have used your web project application and followed the steps using nginx , but am getting 502 bad gateway message.
Then i checked the logs in nginx folder and it showed "No connection could be made because the target machine actively refused it".

Please help me to resolve the issue

Handler "Python FastCGI" has a bad module "FastCgiModule" in its module list

I am trying to follow along the tutorial to run a Django app with IIS server. Here are my settings:
Windows Server 2019, IIS10.

I am setting up my server and added CGI as shown in the image.

Capture1

But, when i deploy the app, i get an error saying that the "FastCgiModule" is not in the list.

Capture2

I looked in HandlerMappings to find that the FastCgiModule was indeed not in the list of modules that IIS considers.

Help and understanding about this is much appreciated.

The FastCGI process exited unexpectedly

I tried the tutorial with exactly the same steps but I still keep getting this error with fastcgi

HTTP Error 500.0 - Internal Server Error
c:\python37\python.exe - The FastCGI process exited unexpectedly

Most likely causes:
•IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
•IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
•IIS was not able to process configuration for the Web site or application.
•The authenticated user does not have permission to use this DLL.
•The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

Things you can try:
•Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.
•Check the event logs to see if any additional information was logged.
•Verify the permissions for the DLL.
•Install the .NET Extensibility feature if the request is mapped to a managed handler.
•Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.

Module : FastCgiModule
Notification: ExecuteRequestHandler
Handler: Python FastCGI
Error Code: 0xc0000409
Requested URL: http://localhost:80/
Physical Path: C:\inetpub\wwwroot
Logon method: Anonymous
Logon User: Anonymous

More Information:
This error means that there was a problem while processing the request. The request was received by the Web server, but during processing a fatal error occurred, causing the 500 error.
View more information »

Microsoft Knowledge Base Articles:
•294807

My system information is as follows:
Windows Server 2016
Python 3.7.7

Python packages:
asgiref 3.2.10
Django 3.0.7
et-xmlfile 1.0.1
jdcal 1.4.1
openpyxl 3.0.3
pip 19.2.3
pytz 2020.1
setuptools 41.2.0
sqlparse 0.3.1
wfastcgi 3.0.0

Internal Server Error - python 3.9 apache 2.4 based on Windows 10

Hi @Johnnyboycurtis
i followed step by step your youtube tutorial but when i start the Apache service and then go via browser to my localhost the page gives me an Internal Server Error. In the Apache log there are 2 particular lines:

[Thu Apr 21 16:56:18.626780 2022] [wsgi:error] [pid 6632:tid 1124] [client ::1:50605] mod_wsgi (pid=6632): Failed to exec Python script file 'C:/project/project/wsgi.py'.
[Thu Apr 21 16:56:18.626780 2022] [wsgi:error] [pid 6632:tid 1124] [client ::1:50605] mod_wsgi (pid=6632): Exception occurred processing WSGI script 'C:/project/project/wsgi.py'.

Any advice?
Thanks!

Should delete those FastCGI steps for IIS and recommend HttpPlatformHandler

Microsoft has deprecated wfastcgi so it shouldn't be used any more.

If people start cleanly with HttpPlatformHandler, the experience should be smooth,

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
        </handlers>
        <httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\python.log" startupTimeLimit="20" processPath="C:\Users\<user name>\AppData\Local\Programs\Python\Python310\python.exe" arguments=".\mysite\manage.py runserver %HTTP_PLATFORM_PORT%">
        </httpPlatform>
    </system.webServer>
</configuration>

Python/Django still takes care of everything including static files, and IIS/HttpPlatformHandler just passes requests on.

More details can be found from my blog post.

help

1-after I deploy my Django project in folder wwwroot could I delete it to prevent customer who buy it from me to reuse it or copy to another

2-could I make a pc or own dedicated computer encrypt folder and act as a local server for many connected pc in a company run by linux?

3-what about statics my project much static and java script will be static root how it works?

Could contact you email?

4- I deployed one project. www.cutisystem.com on DigitalOcean on domain work http but if I put https it naginex error
I use cerbot certificate

deploye multiple Django application on iis

Hello @Johnnyboycurtis I'm trying to host multiple django application on IIS but it's not working.
I saw your video it is very help full, but when I'm trying to host 2nd application on different port in different directory but not working.

I have created separate web.config file for 2nd application, but not running . giving below 500 error.

I also set permission to my application as you mention in your video

It would be great if help me in this I'm trying it from last 3 days but not works.

Please find below attachment of error
CbIqp

Static Files are Not Served Properly by IIS Even After Following Step 8 of the README (Creating a Virtual Directory for Static Files)

Environment
OS: Windows 10 Enterprise Evaluation (VM)
Build: 17763.rs5_release.180914-1434

Replicate

  1. Follow exactly as the README instructs.
  2. Navigate to the admin portal of your newly deployed Django app.
  3. You will notice some CSS and images not loading properly.

Possible Solution
I couldn't get static file configuration in settings.py to be respected by IIS, however, I was able to get IIS to serve static files directly via its own configuration.

  1. After following Step 8 of the README, click on the newly created "static" directory on the left column.
  2. Then double click the Handler Mappings icon.
  3. Then click on the "View Ordered List..." on the right column.
  4. Then click on "StaticFile" which is given least priority, and bump it up via "Move Up" on the right-column until it is top priority.
  5. Now navigate to your Django app and static files should be served properly.

Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding

Hi @Johnnyboycurtis,

Was able to create a working Django application and works fine in development (runserver). However, I'm currently stuck with my production build using Apache as the web server. Unfortunately, I am not able to resolve the issue.

Was able to install the Apache service successfully. However, after adding the Python-related parameters, the service stopped and doesn't want to start/restart. Attached is my httpd.conf and the Apache error log file.

Would it be possible for you to check and share your recommendations on how I can correct this problem?

Thanks a lot for the assistance.

httpd - Copy.txt
error - Copy.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.