首页  >  问答  >  正文

nginx 反向代理 swoole的设置

nginx 反向代理 swoole 的设置问题

首先版本
php 7.1.0
swoole 2.0.5
nginx 1.10.2

按官网说明http://wiki.swoole.com/wiki/p...,设置nginx反向代理到 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;    
    }
}
  1. 访问的 域名/index.php 或者 域名/admin/ 等都没有问题,可以出现swoole代码执行的结果(后台能看到swoole两次访问记录)

  2. 但直接访问 域名 就出现403,(后台看到swoole打印一次访问记录)

  3. 在nginx配置里面添加了try_files $uri $uri/ /index.php?$query_string; 也没有效果

请指点!

其中swoole代码如下(只是打印访问记录):

$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();
習慣沉默習慣沉默2714 天前1106

全部回复(3)我来回复

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 17:10:26

    if(!-e $request_filename)
    满足这个条件才转发至http://127.0.0.1:9501
    显然条件不满足
    文件和目录判断
    -f和!-f判断是否存在文件
    -d和!-d判断是否存在目录
    -e和!-e判断是否存在文件或目录
    -x和!-x判断文件是否可执行

    你只访问域名,“/”是存在的 所以不会转发

    如楼上所说你需要指定一个默认请求文件

    回复
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 17:10:26

    根据你的要求,server 里应有一行

    index index.php;

    回复
    0
  • 漂亮男人

    漂亮男人2017-05-16 17:10:26

    你吧你的后端当google反代就可以了。

    回复
    0
  • 取消回复