簡體   English   中英

在現有的Nginx PHP配置中添加Flask應用

[英]Adding Flask app in existing nginx PHP configuration

下面的配置是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 Tutorial中獲得的,請參閱本章: 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('/flaskapp/')而不是@app.route('/') @app.route('/flaskapp/')

然后@app.route('/view_profile/<username>')成為@app.route('/flaskapp/view_profile/<username>')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM