下面的配置是PHP中Web应用程序的配置,并且可以正常工作(我将该站点的名称伪造为https://sub.mysite.nl)。

server {
        listen [::]:443 ssl ipv6only=on; # managed by Certbot
        listen 443 ssl; # managed by Certbot

        ## some certificate info ##

        root /path/to/www;
        index index.php index.htm index.html;

        server_name sub.mysite.nl;

        location / {
                try_files               $uri $uri/ =404;
        }

        location ~ \.php$ {
                try_files               $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass            unix:/var/run/php/php7.0-fpm.sock;
                fastcgi_index           index.php;
                fastcgi_param           SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include                 fastcgi_params;
        }

        location ~ /\.ht {
            deny all;
        }

        ## some logging info ##

    }

server {
        if ($host = sub.mysite.nl) {
                return 301 https://$host$request_uri;
        } # managed by Certbot

        listen 80 default_server;
        listen [::]:80 ipv6only=on default_server;

        server_name sub.mysite.nl;
        return 404; # managed by Certbot
}


现在我想在子文件夹中添加Flask应用程序,例如https://sub.mysite.nl/flaskapp

下面的代码块是我从Flask Mega教程中学到的,具体参见本章:https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvii-deployment-on-linux(在设置Nginx下)。我想我需要将其放在location /flaskapp/下,但是我不确定如何继续,因为当我执行此操作并转到https://sub.mysite.com/flaskapp时,它会给我404 Not Found

    location /flaskapp {
            proxy_pass http://localhost:8000;
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }


我需要在Flask应用中更改路由吗?

最佳答案

好的,我一直在鬼混,似乎在Flask应用中编辑路线提供了最简单的解决方案。为此,我使用底部原始文章中的Flask nginx块。

因此,我使用的是@app.route('/')而不是@app.route('/flaskapp/')

并且@app.route('/view_profile/<username>')变为@app.route('/flaskapp/view_profile/<username>')

10-06 07:11
查看更多