Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSL support for Swoole HTTP Server not working #155

Closed
viezel opened this issue Apr 9, 2021 · 12 comments
Closed

SSL support for Swoole HTTP Server not working #155

viezel opened this issue Apr 9, 2021 · 12 comments
Assignees

Comments

@viezel
Copy link

viezel commented Apr 9, 2021

  • Octane Version: 0.1.1
  • Laravel Version: 8.36.2
  • PHP Version: 8.0.3
  • Server: Swoole 4.6.4

Description:

When using Swoole HTTP Server directly without nginx as proxy - then we need to configure SSL.

In Swoole it looks like this:

$server = new Swoole\HTTP\Server(
   "0.0.0.0", 
   9501, 
   SWOOLE_PROCESS, 
   SWOOLE_SOCK_TCP | SWOOLE_SSL
);

$server->set([
  'ssl_cert_file' => '/etc/nginx/ssl/direct.example.com/3456789/server.crt',
  'ssl_key_file' => '/etc/nginx/ssl/direct.example.com/3456789/server.key',
  'ssl_ciphers' => 'TLS13-AES-256-GCM-SHA384:TLS13-...', // long string
]);

However, we cannot add the SWOOLE_SSL to the Server arguments in here: https://github.com/laravel/octane/blob/master/bin/createSwooleServer.php#L10

Can we please expose this as a config?

@themsaid
Copy link
Member

themsaid commented Apr 9, 2021

You can use the octane.swoole.options array in the config file to set those.

@themsaid themsaid closed this as completed Apr 9, 2021
@viezel
Copy link
Author

viezel commented Apr 9, 2021

Im talking about this flag SWOOLE_SSL

where do you see that in the options?

@themsaid
Copy link
Member

themsaid commented Apr 9, 2021

@viezel feel free to open a PR. However, I think this flag is only available in some Swoole builds not all. You'll need to check with the Swoole team first.

Undefined constant "SWOOLE_SSL"

@viezel
Copy link
Author

viezel commented Apr 9, 2021

Correct, if you do not enable openssl then it will not work

@viezel
Copy link
Author

viezel commented Apr 9, 2021

This however opens a discussion on which swoole modules that is required enabled by Octane.

pecl install --configureoptions 'enable-sockets="no" enable-openssl="yes" enable-http2="yes" enable-mysqlnd="yes" enable-swoole-json="no" enable-swoole-curl="yes"' swoole

@kiddtang
Copy link
Contributor

kiddtang commented Jul 7, 2021

Created PR for this #342
For those who are looking for how to turn on HTTPS from scratch, can find the tutorial here.

@L3o-pold
Copy link
Contributor

L3o-pold commented Aug 4, 2021

@viezel feel free to open a PR. However, I think this flag is only available in some Swoole builds not all. You'll need to check with the Swoole team first.

Undefined constant "SWOOLE_SSL"

Then why it was merged in #342?

Error  Undefined constant "SWOOLE_SSL"

It was release yesterday as a patch release (https://github.com/laravel/octane/releases/tag/v1.0.9) but for me it's a breaking change.

@kressaty
Copy link

kressaty commented Aug 4, 2021

@L3o-pold I also had this issue using Sail, I had to update Sail, replace my published dockerfile, and sail build to get functionality back. Still throwing some warnings but I think it's due to my supervisor command, though my app does work again.

@sy-records
Copy link
Contributor

Undefined constant "SWOOLE_SSL"

You need to compile Swoole with openssl enabled (--enable-openssl).

@kiddtang
Copy link
Contributor

kiddtang commented Aug 5, 2021

@viezel feel free to open a PR. However, I think this flag is only available in some Swoole builds not all. You'll need to check with the Swoole team first.

Undefined constant "SWOOLE_SSL"

Then why it was merged in #342?

Error  Undefined constant "SWOOLE_SSL"

It was release yesterday as a patch release (https://github.com/laravel/octane/releases/tag/v1.0.9) but for me it's a breaking change.

if $config['swoole'][ssl'] is not defined, it shouldn't turn on openssl and trigger the error.

The quick fix without rebuild, define config/octane.php with

    'swoole' => [
        'ssl' => false,
    ],  

I think it is better to update to latest Laravel Sail version as it is not using PECL to install Swoole.
It is using php8.0-swoole which it faster in building the sail app docker image.

@L3o-pold
Copy link
Contributor

L3o-pold commented Aug 5, 2021

@kiddtang editing config/octane.php is not a solution as https://github.com/laravel/octane/pull/342/files#diff-8579bc8f34b623c394a7220fd2277cb0a8183b6c9a77d99f106f9995c5a6b46dR10 will always use the SWOOLE_SSL constant.

And for my case it was not an issue in dev environment with sail but with a production environment that was not having openssl enabled for Swoole.
IMO it's a breaking change that should not be released like that.

In addition using functional testing (https://laravel.com/docs/8.x/http-tests#making-requests) will not help you to trigger the issue as it's not testing octane unfortunately.

@sts-ryan-holton
Copy link

@L3o-pold I'm getting a similar issue I believe. I'm using Apache vhosts and have generated a let's encryps ssl certificate. How can I serve my application through ssl? I added

'swoole' => [
    'ssl' => true,
    'options' => [
        'ssl_cert_file' => '/etc/letsencrypt/live/icicle-v2.example.org/cert.pem',
        'ssl_key_file' => '/etc/letsencrypt/live/icicle-v2.example.org/privkey.pem',
    ]
],

to my config file. Do I need to? Or should it be completely done via apache because that gives me a connection refused:

<VirtualHost *:80>
    ProxyPreserveHost On

    ProxyPass / http://127.0.0.1:8000/
    ProxyPassReverse / http://127.0.0.1:8000/

    ServerName icicle-v2.example.org
    ServerAdmin admin@localhost
    DocumentRoot /var/www/example/current/public

    <Directory /var/www/example/current/public>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:443>
    ProxyPreserveHost On

    ProxyPass / http://127.0.0.1:8000/
    ProxyPassReverse / http://127.0.0.1:8000/

    ServerName icicle.example.org
    ServerAdmin admin@localhost
    DocumentRoot /var/www/example/current/public;

    <Directory /var/www/example/current/public>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants