search

Home  >  Q&A  >  body text

nginx reverse proxy swoole settings

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;    
    }
}
  1. 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)

  2. But when accessing domain name directly, 403 appears (you can see swoole printing an access record in the background)

  3. 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();
習慣沉默習慣沉默2747 days ago1141

reply all(3)I'll reply

  • 过去多啦不再A梦

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

    if(!-e $request_filename)
    Only forward to http://127.0.0.1:9501 if this condition is met
    Obviously the condition is not met
    File and directory judgment
    -f and!-f judge whether the file exists
    -d and !-d determines whether the directory exists
    -e and !-e determine whether the file or directory exists
    -x and !-x determine whether the file is executable

    You only access the domain name, "/" exists, so it will not be forwarded

    As mentioned above, you need to specify a default request file

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 17:10:26

    According to your requirements, there should be a line in server

    index index.php;

    reply
    0
  • 漂亮男人

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

    You can just use Google as your backend.

    reply
    0
  • Cancelreply