我花了很多小时,看似简单的configuration,但我不知道正确的configuration:(
我有2个不同的应用程序,我必须服务2个不同的url。 这个应用程序下的所有东西都需要抓住所有的index.php。
示例:(公用URL =>服务path(应用程序))
https://example.com/ => /var/public/index.php https://example.com/xy => /var/public/index.php https://example.com/xy/zw => /var/public/index.php
但!
https://example.com/api/v2 => /api/public/index.php https://example.com/api/v2/xy => /api/public/index.php https://example.com/api/v2/xy/test => /api/public/index.php
我也有Apache的反向代理configuration:(仅用于重写/ API / V2到/ api /公共,所以只有nginx / api /公共URI显示 – 反向代理需要,我只有1个公共IP,但许多网站)
<VirtualHost *:443> ServerName xxx.com <Proxy *> Order deny,allow Allow from all </Proxy> SSLEngine On SSLCertificateFile /etc/apache2/cert/xxx.com.pem SSLCertificateKeyFile /etc/apache2/cert/xxx.com.key SSLCertificateChainFile /etc/apache2/cert/yyyy.pem ProxyRequests Off ProxyPreserveHost On RewriteEngine On RewriteRule ^/api/v2$ /api/v2/ [R,L] <Location /api/v2/> ProxyPass http://1.2.3.4/api/public/ KeepAlive=On TimeOut=3600 retry=0 ProxyPassReverse http://1.2.3.4/api/public/ </Location> ProxyPass / http://1.2.3.4/ KeepAlive=On TimeOut=3600 retry=0 ProxyPassReverse / http://1.2.3.4/ LogLevel debug ErrorLog /var/log/apache2/xxx-web-error.log CustomLog /var/log/apache2/xxx-web-access.log common </VirtualHost>
我的configuration不适用于第二部分,只适用于一个确切的path: https : //example.com/api/v2 。
没有执行fastcgi php,我pipe理这个configuration,但是这不适用于dynamicphp。
我的nginxconfiguration:
server { listen 80; #server_name localhost; # main root for GUI #root /api/public; root /var/public; index index.php; location /api/public { alias /api/public; try_files $uri $uri/ /api/public/index.php?$args; #try_files $uri $uri/ /api/public/index.html; location ~ \.php$ { include fastcgi_params; try_files $uri = 404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; } } location / { try_files $uri $uri/ /index.php?$args; #try_files $uri $uri/ /index.html; location ~ \.php$ { include fastcgi_params; try_files $uri = 404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } access_log /var/log/nginx/scripts.log scripts; error_log /var/log/nginx/error.log debug; }
有什么build议?
谢谢!!!
更新 index.php文件的内容:
<html> <body> <?php print "<pre>"; print_r($_SERVER); print "</pre>"; ?> </body> </html>
我变了:
location /api/public
=> location ~ ^/api/public
根据location /api/public
更改
try_files $uri $uri/ /api/public/index.php?$args;
至
try_files $uri $uri/ /index.php?$args;
而且最重要! 更改location /
为此:
location / { try_files $uri $uri/ /index.php?$args; #try_files $uri $uri/ /index.html; location ~ \.php$ { set $php_root $document_root; if ($request_uri ~ ^/api/public) { set $php_root /api/public; } include fastcgi_params; try_files $uri = 404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name; } }
加块是:
set $php_root $document_root; if ($request_uri ~ ^/api/public) { set $php_root /api/public; }
当然,将$document_root
更改为$php_root