[英]Nginx Reverse Proxy for node server returning 404 for css/js files
I'm trying to setup a node server for wiki.js with a NGINX reverse proxy.我正在尝试使用 NGINX 反向代理为 wiki.js 设置节点服务器。 I followed the wiki.js installation instructions and have the files extracted into /var/www/site/main/wiki
so the file structure looks as follows:我按照 wiki.js 安装说明将文件解压到/var/www/site/main/wiki
因此文件结构如下所示:
var
- www
- site
- main
- wiki
-assets
-config.yml
-LICENSE
-node_modules
-package.json
-server
I can run the node server
command in that directory and it instructed me to continue the setup by going to http://localhost:3000
.我可以在该目录中运行node server
命令,它指示我通过转到http://localhost:3000
继续设置。 I then tried to visit the site by it's domain, and the page title is being set to wiki.js Setup
so something is passing through the Nginx proxy, but all css/js files are returning a 404 error causing the page to fail to render.然后我尝试通过它的域访问该站点,并且页面标题被设置为wiki.js Setup
因此某些内容正在通过 Nginx 代理传递,但所有 css/js 文件都返回 404 错误,导致页面无法呈现.
I used a setup from https://nginxconfig.io to configure the Nginx proxy, and the server block is as follows:我使用了https://nginxconfig.io的 setup 来配置 Nginx 代理,服务器块如下:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
# SSL
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
# security
include nginxconfig.io/security.conf;
# reverse proxy
location / {
proxy_pass http://127.0.0.1:3000;
# This next block is actually include with a include
# nginxconfig.io/proxy.conf call but this is the contents of that file
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
# additional config
include nginxconfig.io/general.conf;
}
# subdomains redirect
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name *.example.com;
# SSL
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
return 301 https://example.com$request_uri;
}
# HTTP redirect
server {
listen 80;
listen [::]:80;
server_name .example.com;
include nginxconfig.io/letsencrypt.conf;
location / {
return 301 https://example.com$request_uri;
}
}
I just ran into this issue myself.我自己刚刚遇到了这个问题。 After poking and prodding, I found there are multiple issues with the nginxconfig.io setup;经过一番摸索,我发现 nginxconfig.io 设置存在多个问题; it seems to want to configure too many things and this gets in the way of wiki.js actually being able to do its own thing.它似乎想要配置太多东西,这妨碍了 wiki.js 实际上能够做自己的事情。
As of right now (2020-05-16_14-11) these are valid working server blocks:截至目前(2020-05-16_14-11),这些是有效的工作服务器块:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name wiki.domain.invalid;
# SSL
ssl_certificate /etc/letsencrypt/live/wiki.domain.invalid/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/wiki.domain.invalid/privkey.pem; #managed by Certbot
ssl_trusted_certificate /etc/letsencrypt/live/wiki.domain.invalid/chain.pem;
# security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
#add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
add_header Strict-Transport-Security "max-age=0" always;
# . files
location ~ /\.(?!well-known) {
deny all;
}
# logging
access_log /var/log/nginx/wiki.domain.invalid.access.log;
error_log /var/log/nginx/wiki.domain.invalid.error.log warn;
# reverse proxy
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
#proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto $scheme;
#proxy_set_header X-Forwarded-Host $host;
#proxy_set_header X-Forwarded-Port $server_port;
proxy_next_upstream error timeout http_502 http_503 http_504;
}
# gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
}
# HTTP redirect
server {
listen 80;
listen [::]:80;
server_name wiki.domain.invalid;
# ACME-challenge
location ^~ /.well-known/acme-challenge/ {
root /var/www/_letsencrypt;
}
location / {
return 301 https://wiki.domain.invalid$request_uri;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.