nginx reverse proxy swoole setting problem
First version
php 7.1.0
swoole 2.0.5
nginx 1.10.2
According to the official website instructions http://wiki.swoole.com/wiki/p..., set nginx reverse proxy to swoole,
server {
root /alidata/www/vweb/;
server_name 域名;
location / {
#添加了这个也不行
#try_files $uri $uri/ /index.php?$query_string;
#下面这几行是swoole官网设定
if (!-e $request_filename) {
proxy_pass http://127.0.0.1:9501;
}
proxy_http_version 1.1;
proxy_set_header Connection "keep-alive";
proxy_set_header X-Real-IP $remote_addr;
}
}
There is no problem with the accessed domain name/index.php or domain name/admin/, and the results of swoole code execution can appear (swoole two access records can be seen in the background)
But when accessing domain name directly, 403 appears (you can see swoole printing an access record in the background)
Added try_files $uri $uri/ /index.php?$query_string; in nginx configuration but it has no effect
Please give me some advice!
The swoole code is as follows (just print access records):
$http = new swoole_http_server("127.0.0.1", 9501);
$http->on('request', function ($request, $response) {
echo '-------------------Request---#'.rand(1000, 9999).'------------------'."\n";
$response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
});
$http->start();
if(!-e $request_filename)
满足这个条件才转发至http://127.0.0.1:9501
显然条件不满足
文件和目录判断
-f和!-f判断是否存在文件
-d和!-d判断是否存在目录
-e和!-e判断是否存在文件或目录
-x和!-x判断文件是否可执行
你只访问域名,“/”是存在的 所以不会转发
如楼上所说你需要指定一个默认请求文件
根据你的要求,server 里应有一行
index index.php;
你吧你的后端当google反代就可以了。