我正在尝试使用 Flask 部署我的网站。一切都在本地完美运行(localhost:5000),但是当我将其部署到远程 linux ubuntu 服务器(www.linode.com)时,我遇到了问题。我已经安装了gunicorn和nginx,但是我的CSS文件没有被考虑到,因此,我的网页只是单独显示为HTML内容,没有形状/颜色等。
我对 Web 开发非常陌生,我不明白为什么它在本地运行得很好,而在 Linux 服务器上不再(不完全)运行。问题是否与无法在 HTML 和 CSS 之间进行链接的 nginx 有关?因为在本地我不需要使用 nginx,一切正常。
这是我输入 sudo nano /etc/nginx/sites-enabled/assets 时的 nginx 配置文件:
server {
listen 80;
server_name 45.79.250.111;
include /etc/nginx/mime.types;
location /static {
alias /home/gardy/ladybird_site/assets/static;
}
location / {
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
proxy_redirect off;
}
}
这是我的网站目录树:
ladybird_site/
requirements.txt
run.py
assets/
__init__.py
config.py
models.py
fonts/
et-line.eot
...
fontawesome-webfont.woff2
main/
routes.py
__init__.py
templates/
index.html
layout.html
static/
css/
animate.css
bootstrap.min.css
font-awesome.min.css
style.css
bxslider/
jquery.bxslider.css
images/
bx_loader.gif
controls.png
et-line-font/
style.css
magnific-popup/
magnific-popup.css
owl-carousel/
owl.carousel.css
owl.theme.css
owl.transitions.css
images/
ldb_ico.ico
founder_pics/
custom_pics/
f1.jpg
f2.jpg
f3.jpg
ldb_imgs/
1.png
2.png
3.png
js/
bootstrap-hover-dropdown.min.js
bootstrap.min.js
...
jquery.bxslider.min.js
main.js
我对这些东西感到疯狂,两天来尝试和修改,没有显着的改进,并且在互联网上找不到答案......
非常感谢
您的静态路径看起来不错。您已将服务器设置为侦听端口 80,这是 HTTP 的默认端口,但可能您尚未打开它。下一步是打开它。
sudo ufw allow http/tcp
您提到您的服务器仍在侦听端口 5000。但是,如果您完成了测试,您可以禁止 Nginx 使用此端口。
sudo ufw delete allow 5000
通过运行以下命令启用这些新规则:
sudo ufw enable
# Hit 'y' for 'yes' when prompted
最后,您现在可以重新启动 Nginx 服务器:
sudo systemctl status nginx.service
如果您导航到应用程序的 IP 地址并附加
static/css/style.css
,您应该能够访问您的 CSS 文件。我是说http://<your IP address>/static/css/style.css
我遇到了同样的问题,并通过将 /etc/nginx/nginx.conf 中的用户更改为当前用户来解决它。
user www-data;
作者:user your_username;