Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6608149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:34:45+00:00 2026-05-25T19:34:45+00:00

I’d like to have a static site in my root public_html directory, then Flask

  • 0

I’d like to have a static site in my root public_html directory, then Flask apps in their own subdirectories (e.g. public_html/foo). The static root directory functions as expected.

I have spent hours editing the nginx configuration to get the Flask apps working, but always end up back in the same place, namely that the following code always returns ‘Bad Config’ when I migrate to mysite/foo. I want it to return ‘Hello World!’

If I alter the nginx configuration so that the server root is in public_html/foo, the Flask applications work as expected (i.e. mysite.com returns ‘Hello World!’). In the following configuration, the Flask index still points to mysite.com when I believe it should point to mysite.com/foo

/etc/nginx/sites-enabled/mysite

upstream frontends {
# gunicorn
server 127.0.0.1:18000;
}

server {
listen 80;
server_name www.mysite.com;
rewrite ^/(.*) http://mysite.com$1 permanent;
}

server {
listen 80;
server_name mysite.com;
server_name_in_redirect off;
root /home/ubuntu/public_html/mysite;

access_log /home/ubuntu/logs/mysite/access.log;
error_log /home/ubuntu/logs/mysite/error.log;

location / {
    index index.html;
    }
location /foo {
    try_files $uri @foo;
    }
location @foo {
        proxy_pass http://frontends;
        break;
    }
}

/home/ubuntu/public_html/mysite/foo/foo.py

from flask import Flask
from flask import render_template
app = Flask(__name__)

@app.route('/')
def index():
    return 'Hello World!'

@app.route('/foo')
def test():
    return 'Bad config'

@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404

if __name__ == '__main__':
    app.run()

/home/ubuntu/public_html/mysite/foo/deploy.py

workers = 2
bind = '127.0.0.1:18000'
proc_name = 'foo_gunicorn'
pidfile = 'foo.pid'

Flask is launched with gunicorn -c deploy.py foo:app

Update

Adding rewrite /foo/(.*) /$1 break; to the nginx location /foo block makes mysite/foo return ‘Hello World’, however all its links (such as those to the stylesheet from a template) still point to the site root (e.g. mysite/static/style.css instead of mysite/foo/static/style.css)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:34:45+00:00Added an answer on May 25, 2026 at 7:34 pm

    Got an answer from mitsuhiko (Flask lead dev):
    http://flask.pocoo.org/snippets/35/

    You need to define a ReverseProxied class in your Flask app and add several proxy-set-header lines to the location /foo block in the nginx config.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I have some data like this: 1 2 3 4 5 9 2 6
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.