我试图configuration两个应用程序由nginx提供。 第一个似乎工作正常,我重复了第二个configuration,但我有一些问题。
我正在使用套接字运行由Unicorn支持的Sinatra服务器来传递上游信息。 我可以到达根域(api.richardson.co.nz),一切似乎工作正常,但只要我尝试访问根域(api.richardson.co.nz/games)path得到一个“找不到”的错误。
这是我的nginx conf文件:
worker_processes 1; user nginx web; pid /tmp/nginx.pid; error_log /var/www/knowyourgenre.com/shared/log/nginx.error.log; events { worker_connections 1024; # increase if you have lots of clients accept_mutex off; # "on" if nginx worker_processes > 1 use epoll; # enable for Linux 2.6+ } http { include mime.types; default_type application/octet-stream; access_log /tmp/nginx.access.log combined; sendfile on; tcp_nopush on; # off may be better for *some* Comet/long-poll stuff tcp_nodelay off; # on may be better for some Comet/long-poll stuff gzip on; gzip_http_version 1.0; gzip_proxied any; gzip_min_length 500; gzip_disable "MSIE [1-6]\."; gzip_types text/plain text/html text/xml text/css text/comma-separated-values text/javascript application/x-javascript application/atom+xml; upstream app_server { server unix:/var/www/knowyourgenre.com/current/unicorn.sock fail_timeout=0; server localhost:8080 fail_timeout=0; } upstream api { server unix:/var/www/api/unicorn.sock fail_timeout=0; server localhost:8081 fail_timeout=0; } server { listen 80; # for Linux client_max_body_size 4G; server_name .knowyourgenre.com; keepalive_timeout 5; root /var/www/knowyourgenre.com/current/public/; try_files $uri/index.html $uri.html $uri @app; location @app { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://app_server; } error_page 500 502 503 504 /500.html; location = /500.html { root /path/to/app/current/public; } } server { listen 80; # for Linux client_max_body_size 4G; server_name .richardson.co.nz; keepalive_timeout 5; root /var/www/api; try_files $uri/index.html $uri.html $uri @app; location @app { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://api; } # Rails error pages error_page 500 502 503 504 /500.html; location = /500.html { root /path/to/app/current/public; } } }
上游服务器中的错误是否会导致“找不到”被返回? 我很确定一切都在Sinatra服务器内工作,但我可能错过了一些东西。
在根值的末尾添加一个斜杠。
root /var/www/api/;
另外,我build议在一个位置打包“try_files”。
location / { try_files $uri/index.html $uri.html $uri @app; }