简体   繁体   中英

Redirect eventsource request to server port that runs swoole

I'm trying to improve my php application using Swoole for fetch notifications. As swoole runs in PHP's built in server, I'm trying to redirect my 'host/notification' requests to port 9501 where Swoole is running without success. My code in .htaccess follows below:

# redirect to 9501 if "messages/" is matched
RewriteCond %{SERVER_PORT} !^9501$
RewriteRule ^notification(.*[^/])/?$ https://%{HTTP_HOST}:9501

Is it correct to try to use this approach or since the built in server has nothing to do with Apache that is not possible?

Thanks in advance

If you have Nginx in front of the Apache server you can use it to "redirect" the traffic to Swoole. The idea is to use it as proxy, not to make a redirect, as if the request to the URL is a POST request, then you will loose your POST data on redirect.

So in your Nginx file your can add an extra line like:

server {
    ...

    location /notification/ {
        proxy_pass http://127.0.0.1:9501;
    }

    ...
}

Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM