Nginx:使用反向代理无法正确呈现静态资产path

我有困难configuration反向代理将用户从http://localhost/nexus/http://localhost:8081/

我目前的nginx.conf如下所示:

 worker_processes 4; events { worker_connections 1024; } http { server { listen 80; location /nexus/ { proxy_pass http://localhost:8081/; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } } 

当我点击http://localhost/nexus/ ,它部分呈现页面。

当我检查HTML源代码时,我注意到JavaScript链接,图像链接和样式表链接没有正确构build。

例如,我看到这个:

 <link rel="stylesheet" type="text/css" href="http://localhost/static/rapture/resources/loading-prod.css?_v=3.3.1-01"> <script type="text/javascript" src="http://localhost/static/rapture/baseapp-prod.js?_v=3.3.1-01"></script> <img id="loading-logo" src="http://localhost/static/rapture/resources/images/loading-logo.png?_v=3.3.1-01"/> 

…但是,应该是这样的: –

 <link rel="stylesheet" type="text/css" href="http://localhost/nexus/static/rapture/resources/loading-prod.css?_v=3.3.1-01"> <script type="text/javascript" src="http://localhost/nexus/static/rapture/baseapp-prod.js?_v=3.3.1-01"></script> <img id="loading-logo" src="http://localhost/nexus/static/rapture/resources/images/loading-logo.png?_v=3.3.1-01"/> 

我的nginx.conf应该如何让页面的其余部分正确渲染?

非常感谢你。

你需要configuration你的nginx直接提供静态文件:

 location /static { root /path/to/static/files; } 

nginx进程将需要对static子树中的所有文件及其父目录的读许可权。