DEV Community

Discussion on: Deploy Flask The Easy Way With Gunicorn and Nginx!

Collapse
 
byterbit profile image
Byter-Bit

Without placing an "index.html" file in the folder I get a "2 directory index of "/var/www/html/myproject2/" is forbidden"
I've tried changing the user and group to www-data and, as a last resort, running "sudo chmod -R 777 myproject2" and then restarting nginx.

When I do place an "index.html" file there it runs, and not the python file.
I am attempting to run the program on an external Ubuntu server using the ip address followed by /myproject2, as in xxx.xxx.xx.xx/myproject2

At least this shows the redirection to the folder is working -
I must say this has been rather hard to debug - more moving parts than I'm used to with Apache running PHP or Node files -
Yours seems to be the best written tutorial I've found. I've spent days running several others and getting nowhere :>(

Collapse
 
brandonwallace profile image
brandon_wallace

Byter-Bit,

There is no need to set the permissions to 777. If you would like to access the /myproject2 route you must create a route in Flask. Look at the @app.route(...) line in the code. The route you need would look something like this:

Example 1:

@app.route('/myproject2')
def custom_route():
    '''Myproject2 page route'''

    return '<h1>My Project 2</h1>'
Enter fullscreen mode Exit fullscreen mode

Then in your browser you would access this custom route like this http://<ip_address>/myproject2. If you set the server_name line in Nginx you would use http://<domain_name>/myproject2 to access that page.

Example 2:

@app.route('/')
def index():
    '''Index page route'''

    return '<h1>Application Deployed!</h1>'
Enter fullscreen mode Exit fullscreen mode

The index route is accessible like this http://<ip_address> or if you set up Nginx you would use this http://<domain_name>.