【发布时间】:2020-07-06 08:58:58
【问题描述】:
我想获取一些用户输入,运行几行 Python,然后在网络上显示结果。
我有一个指向 DigitalOcean 上的服务器的域,并且正在学习本教程:https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-18-04
我已经完成了本教程并且它确实有效,但是我当然希望我的网站不要被短语“Hello there!”完全覆盖。我想在非根位置显示结果,例如https://example.com/myproject/。
我已经使用 Let's Encrypt & CertBot 保护了我的域。
我正在使用一个名为 default 的单个 nginx 配置文件 - 我完全遵循了本教程的其余部分。问题似乎出在 proxy_pass 指令中。当我将它移动到 / 位置块时,它可以工作,并且我的索引页面被“Hello there!”覆盖。当我将 proxy_params 和 proxy_pass 移动到 /myproject/ 位置块时,我收到 404 错误。我尝试了一些方法并试图更好地理解位置块,但无济于事。
这里是 Nginx 配置文件:
# Default server configuration
#
server {
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php;
server_name example.com www.example.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location /myproject/ {
include proxy_params;
proxy_pass http://unix:/home/jackson/myproject/myproject.sock;
}
# pass the PHP scripts to FastCGI server
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
任何帮助将不胜感激。谢谢!
【问题讨论】:
标签: python nginx flask reverse-proxy gunicorn