我正在尝试在HHVM前面configurationnginx来提供一个API,其中有一个登陆页面列出了/中的可用版本,以及/ api / [version] /中实际安装的API版本。
到目前为止,我的nginxconfiguration如下:
server { listen *:80; server_name api.domain.com; # Character Set charset utf-8; # Logs access_log /www/vhosts/api.domain.com/logs/access_log.nginx; error_log /www/vhosts/api.domain.com/logs/error_log.nginx; # Directory Indices index index.php; # Document Root root /www/vhosts/api.domain.com/public; # Location location /assets { try_files $uri $uri/ =404; } location /api/1.0 { root /www/vhosts/api.domain.com/api/1.0/public; rewrite ^/api/1.0(.*)$ /index.php$1; try_files $uri $uri/ /index.php?$query_string; } location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { log_not_found off; access_log off; } # Error Pages error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location ~ \.(hh|php)$ { fastcgi_keep_conn on; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # Block access to .htaccess location ~ \.ht { deny all; } }
请求http://api.domain.com/正确地提供login页面,但是http://api.domain.com/api/1.0/foo请求仍然通过/www/vhosts/api.domain.com/public/index.php index.php发送到index.php, /www/vhosts/api.domain.com/public/index.php而不是/www/vhosts/api.domain.com/api/1.0/public/index.php 。
有谁知道我可以如何解决这个问题? 我正在切换的Apacheconfiguration在下面供参考:
<VirtualHost *:80> ServerAdmin [email protected] ServerName api.domain.com DocumentRoot /www/vhosts/api.domain.com/public/ <Directory /www/vhosts/api.domain.com/public/> Options -Indexes FollowSymLinks AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /www/vhosts/api.domain.com/logs/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /www/vhosts/api.domain.com/logs/access.log combined ServerSignature Off Alias /api/1.0 "/www/vhosts/api.domain.com/api/1.0/public/" <Directory /www/vhosts/api.domain.com/api/1.0/public/> Options -Indexes FollowSymLinks AllowOverride All Order allow,deny allow from all </Directory> Alias /api/latest "/www/vhosts/api.domain.com/api/1.0/public/" SetEnv APPLICATION_ENV testing </VirtualHost>
在一个不相关的说明中,有人可以为我标记这个hhvm吗? 我至less需要300个声望才能创build标签,显然没有人在这里问过有关hhvm的问题。 :/
编辑:
按照下面的krisFR的build议,我试着修改location /api/1.0块,如下所示:
location /api/1.0 { alias /www/vhosts/api.domain.com/api/1.0/public; try_files $uri $uri/ /index.php?$query_string; }
但是,这会从/www/vhosts/api.domain.com/public/index.php加载代码,而不是我想要加载的代码/www/vhosts/api.domain.com/api/1.0/public/index.php 。 还有什么想法?
源https://stackoverflow.com/questions/20426812/nginx-try-files-alias-directives
这是nginx中的一个长期存在的错误 。 但是你可以通过再次使用root指令来解决。 一种黑客,但至less是有效的。
同时,我会添加一个斜线位置指令。
location /api/1.0/ { root /www/vhosts/api.domain.com/api/1.0/public/; try_files $uri $uri/ /index.php?$query_string; }
NGinx也有一个别名指令。
试一试 :
location /api/1.0/ { alias /www/vhosts/api.domain.com/api/1.0/public/; ... }
编辑:
你可以试试这个:
location ^~ /api/1.0/ { alias /www/vhosts/api.domain.com/api/1.0/public/; ... }