我有一个服务运行在一些随机域名(让我们说example.com ),我想从我的本地机器(又名localhost )做一个简单的外观。
location /some-app { # This is for LDAP auth, not sure if important auth_ldap_servers ldapserver; proxy_pass http://example.com; }
我确定它会将我的请求redirect到example.com页面,但是它不会从example.com索引中获取链接的文件,如CSS和JavaScript文件。 我得到像这样的东西:
172.17.0.1 - [email protected] [11/Aug/2016:10:20:35 +0000] "GET /components/navbar/navbar.controller.js HTTP/1.1" 404 570 "http://localhost:8080/some-app" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"
我曾尝试玩proxy_set_header Host $host; ,但似乎没有任何区别。 我很确定我错过了一些显而易见的东西,但是我不知道是什么。 我已经看到了rewrite规则,但我认为这可能比这更容易。
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; ldap_server ldapserver { # boring ldap config } ldap_server ldapserver2 { # boring ldap config } server { listen 80; server_name localhost; error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; auth_ldap_servers ldapserver; location / { root html; index index.html index.htm; } location /some-app { auth_ldap_servers ldapserver2; proxy_pass http://example.com:9000; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
编辑:根据评论更新。
以下configuration服务器只有nginx的index.html ,所有其他的请求都被传递给应用服务器。
代替:
location / { root html; index index.html index.htm; } location /some-app { auth_ldap_servers ldapserver2; proxy_pass http://example.com:9000; }
你应该使用:
location / { root html; index index.html index.htm; } location ~ ^/(.+)$ { auth_ldap_servers ldapserver2; proxy_pass http://example.com:9000; }