在一个小团队(最多30人)的服务器上,我安装了几个可以从浏览器访问的服务。 我想用nginx,因为我认为它更轻量级。
所有的服务/应用程序都是独立testing,并完成他们的工作。 但是当把它们放在一起被子文件夹(比如teamserver.local / service1,或者teamserver.local / service2)分开的时候,在重写规则和代理传递的时候,我感到非常挣扎。
我只是不能让子文件夹configuration工作。
这是我的默认configuration:
server { listen 80; server_name teamserver.local; rewrite ^ https://$http_host$request_uri? permanent; # redirect to https! } server { listen 443; server_name teamserver.local; root /var/www; ssl on; ssl_certificate /etc/nginx/ssl/server.crt; ssl_certificate_key /etc/nginx/ssl/server.key; ssl_session_timeout 5m; ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES"; ssl_prefer_server_ciphers on; location /service1 { fastcgi_pass 127.0.0.1:8000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param HTTPS on; fastcgi_param HTTP_SCHEME https; access_log /var/log/nginx/seahub.access.log; error_log /var/log/nginx/seahub.error.log; } location /seafhttp { rewrite ^/seafhttp(.*)$ $1 break; proxy_pass http://127.0.0.1:8082; client_max_body_size 0; proxy_connect_timeout 36000s; proxy_read_timeout 36000s; } location /media { rewrite ^/media(.*)$ /media$1 break; root /home/seafile/seafile/seafile-server-latest/seahub; } location ~ ^/openproject(/.*|$) { alias /home/openproject/openproject/public$1; access_log /var/log/nginx/openproject/openproject.access.log; error_log /var/log/nginx/openproject/openproject.error.log; passenger_ruby /home/openproject/.rvm/gems/ruby-2.1.4/wrappers/ruby; passenger_base_uri /openproject; passenger_app_root /home/openproject/openproject; passenger_document_root /home/openproject/openproject/public; passenger_user openproject; passenger_enabled on; } location /ldap { rewrite ^/ldap(.*)$ /$1 break; root /usr/share/phpldapadmin/htdocs; index index.php index.html index.htm; # With php5-fpm: #fastcgi_pass unix:/var/run/php5-fpm.sock; #fastcgi_index index.php; #include fastcgi_params; } location /musik { rewrite /musik(.*) /$1 break; proxy_pass http://127.0.0.1:6680; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect off; } }
我很确定,设置正确的根指令和/或nginxparsing位置的顺序是错误的。 我只是不明白。
这里很确定,nginx正在searchroot指令。 问题是:为什么?
我对nginx很新,不想保持凌乱,“每一个服务都有它的端口,只要用这个!” 心理。
一如既往,如果有人指出问题,我会很高兴。 阅读nginx的手册和模块的参考没有帮助我,虽然我已经找出了一些错误,并修复了这些..所以,任何帮助,慷慨赞赏。
使用alias而不是root 。 例如alias /path/to/ldap 。
root指令的问题是location指令之后的path被追加到root指令path的末尾。
例如,你的情况:
location /ldap { root /usr/share/phpldapadmin/htdocs; }
意味着nginx会在/usr/share/phpldapadmin/htdocs/ldap/index.html位置查找URL http://server/ldap/index.html 。
使用alias /usr/share/phpldapadmin/htdocs; ,nginx在/usr/share/phpldapadmin/htdocs/index.html位置查找相同的URL。