当前位置:首页>开发>正文

如何为thinkjs静态资源配置nginx反向代理

2023-04-28 16:12:41 互联网 未知 开发

 如何为thinkjs静态资源配置nginx反向代理

如何为thinkjs静态资源配置nginx反向代理

为了让网站静态资源加载更快,所以需要在VPS的nginx上配置一个反向代理来直接让Nginx处理静态资源,动态类的请求通过反向代理让Node.js来处理:
?
server {
listen 80
server_name abc.com www.abc.com
index index.js index.html index.htm
if ($host != abc.com ) {
rewrite ^/(.*)$ http: //abc.com/$1 permanent
}
root /www/web/myproject/public_html/www
if ( -f $request_filename/index.html ){
rewrite (.*) $1/index.html break
}
if ( !-f $request_filename ){
rewrite (.*) /index.js
}
location = /index.js {
#proxy_http_version 1.1
proxy_set_header Connection ""
proxy_set_header X-Real-IP $remote_addr
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for
proxy_set_header Host $http_host
proxy_set_header X-NginX-Proxy true
proxy_pass http: //127.0.0.1:8363$request_uri
proxy_redirect off
}
location ~ .*.(js|css|gif|jpg|jpeg|png|bmp|swf|ico|svg|cur|ttf|woff)$ {
expires 1000d
}
}
如果是你的项目,需要改动如下地方:
server_name abc.com www.abc.com 将abc.com www.abc.com改为项目对应的域名
root /www/web/myproject/public_html/www 配置项目的根目录,一定要到www目录下
proxy_pass http://127.0.0.1:8363$request_uri将端口6666改为项目里配置的端口

最新文章