我在symfony4上开发了一个api,并使用LexikJWTAuthenticationBundle管理令牌。
在localhost中,一切正常,但在我的测试服务器(强奸pi,apache,https上的ubuntu mate)上,服务器向我发送了401错误和无效的JWT令牌。
正如自述文件(https://github.com/lexik/LexikJWTAuthenticationBundle/blob/master/Resources/doc/index.md#generate-the-ssh-keys)所述,我尝试添加
SetEnvIf Authorization "(. *)" HTTP_AUTHORIZATION = $ 1
配置我的虚拟主机并重新启动apache,但这并没有任何改变。
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/current/rest_api/public
<Directory /var/www/html/current/rest_api/public>
# enable the .htaccess rewrites
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName mydomain
SSLCertificateFile /etc/letsencrypt/live/mydomain/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</VirtualHost>
</IfModule>
感谢您的帮助
答案 0 :(得分:0)
通过以下方式生成private.pem解决了问题:
$ mkdir -p config/jwt
$ openssl genrsa -out config/jwt/private.pem -aes256 4096
$ openssl rsa -pubout -in config/jwt/private.pem -out config/jwt/public.pem
代替
$ mkdir -p config/jwt
$ openssl genpkey -out config/jwt/private.pem -aes256 -algorithm rsa -pkeyopt rsa_keygen_bits:4096
$ openssl pkey -in config/jwt/private.pem -out config/jwt/public.pem -pubout
解决方案: https://github.com/attineos/tutotrompe/tree/master/tutotrompe-ep2