【发布时间】:2019-06-11 22:02:23
【问题描述】:
我使用 nginx 来提供静态文件,并代理到后端 java 服务器。我在后端 java 服务器中使用模板语言,最终将替换所有 html 文件。
我不知道 nginx,所以我想就最有效的方法寻求帮助。
文件:
/assets // Lots more files in this folder
/index.html
/android-chrome-192x192.png
/android-chrome-512x512.png
/apple-touch-icon.png
/browserconfig.xml
/favicon.ico
/favicon-16x16.ico
/favicon-32x32.ico
/mstile-15x150.png
/safari-pinned-tab.svg
/site.webmanifest
到目前为止,这是我的 conf 文件。我提供静态文件,但不代理:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /root/web;
index index.html;
server_name _;
location /assets/ {
try_files $uri =404;
sendfile on;
sendfile_max_chunk 512k;
}
location / {
try_files $uri =404;
sendfile on;
sendfile_max_chunk 512k;
}
location ~* \.(jpg|jpeg|png|gif|ico|webp|mp4)$ {
expires 30d;
}
location ~* \.(css|js)$ {
expires 10d;
}
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied any;
gzip_types application/javascript application/json application/x-font-ttf font/opentype image/* text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";
gunzip on;
# error_log /root/nginx-log.txt debug;
}
我的后端服务器将提供具有以下模式的网址:
/basic-url-here // This style will serve html files built with a templating language from the server, so they need to be at the root path
/api/*
什么是使用 nginx 提供所有这些文件同时还代理到后端服务器的正确/有效方式?
【问题讨论】:
标签: nginx nginx-reverse-proxy nginx-config