.Net Core 3.0 Nginx 不提供静态文件 [英] .Net Core 3.0 Nginx not serving static files
问题描述
我有一个 .net core 3.0 Web 应用程序,我想在 Debian Buster 服务上运行它.我按照微软的说明找到了 这里.
I have a .net core 3.0 web application that I want to run on a Debian Buster service. I followed the Microsoft instructions found Here.
我能够让 Nginx 为页面提供服务,但没有显示任何样式.
I was able to get Nginx to serve the pages however none of the styles are showing up.
配置文件
服务器{听80;server_name yourdomain.com;返回 301 https://$host$request_uri;}
server { listen 80; server_name yourdomain.com; return 301 https://$host$request_uri; }
server {
listen 80;
server_name demo.cerebral.local;
#ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
#ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
#ssl on;
#ssl_session_cache builtin:1000 shared:SSL:10m;
#ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
#ssl_prefer_server_ciphers on;
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
#gzip_types text/plain text/html text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6].(?!.*SV1)";
#access_log /var/log/nginx/demo.access.log;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
我不确定我做错了什么.请把我推向正确的方向.
I am not sure what I am doing wrong. Please push me in the right direction.
推荐答案
如果有人对此解决方案感兴趣,我必须为静态文件显式设置一个位置块
If anyone is interested in the solution I had to explicitly set a location block for the static files
server {
listen 80;
server_name demo.cerebral.local;
#ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
#ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
#ssl on;
#ssl_session_cache builtin:1000 shared:SSL:10m;
#ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
#ssl_prefer_server_ciphers on;
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
#gzip_types text/plain text/html text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6].(?!.*SV1)";
#access_log /var/log/nginx/demo.access.log;
# This location block fixed my issue.
location ~* /(css|js|lib) {
root /var/www/demo/wwwroot;
}
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
这篇关于.Net Core 3.0 Nginx 不提供静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!