I'm facing some problem in mercure trying to push my projet in production. In HTTP all work good but in HTTPS no so I show you all file can help you to understand my problem to solve it.
web:
build:
context: .
target: Symfony_PHP
container_name: web_symfony
ports:
- 80:80
- 443:443
restart: always
volumes:
- ./project/:/var/www/project:delegated
- symfony-var:/var/www/project/var/
- symfony-vendor:/var/www/project/vendor/
networks:
- dev
mercure:
image: dunglas/mercure
container_name: mercure
restart: unless-stopped
environment:
# SERVER_NAME: ':80'
MERCURE_PUBLISHER_JWT_KEY: '${MERCURE_PUBLISHER_JWT_KEY}'
MERCURE_SUBSCRIBER_JWT_KEY: '${MERCURE_SUBSCRIBER_JWT_KEY}'
ports:
- 7001:80
volumes:
- caddy_data:/data
- caddy_config:/config
networks:
- dev
my Apache2 config (docker):
<VirtualHost *:80>
ServerName mysite.net
ServerAlias project
DocumentRoot /var/www/project/public
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
RewriteEngine on
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName mysite.net
ServerAdmin webmaster@localhost
DocumentRoot /var/www/project/public
ErrorLog ${APACHE_LOG_DIR}/errorproject.log
CustomLog ${APACHE_LOG_DIR}/accessproject.log combined
SSLCertificateFile /etc/ssl/certs/project_certs.crt
SSLCertificateKeyFile /etc/ssl/private/project_key.key
</VirtualHost>
</IfModule>
When I try to connect to https://localhost:7001/.well-known/mercure => don't work
http://localhost:7001/.well-known/mercure => redirect me to http://localhost:80/.well-known/mercure
http://localhost/.well-known/mercure => symfony error no route find
How can I run it in HTTPS?
Thanks you in advice for your help
CodePudding user response:
I had the same problem 6 months ago and i did not find any solution to this issue unfortunately
you can allow http in your symfony project for the specific mercure url
in my case i used PUSHER instead of mercure
if you find any solution pls share it
CodePudding user response:
your service mercure is using https (because SERVER_NAME: ':80'
is commented), so it's listening on it's 443 port for incoming https requests, you should add a mapping ports on your mercure service like:
- 7002:443
then try https://localhost:7002/.well-known/mercure
after that, when you try to subscribe to topics, mostly you will have an cors error, and you will have to add this configuration to your mercure service
MERCURE_EXTRA_DIRECTIVES: |-
cors_origins "https://localhost"
anonymous
you will need also add http://localhost to cors_origins if you want to serve you app with http and https (your apache conf)
finally here is an working symfony mercure configuration if want to see more https://github.com/yassinefikri/mediastic/blob/master/docker-compose.yml
CodePudding user response:
Thanks you for the reply so cool
Its work for publishing something but the real issue is that corrs. i have done what you telling me (@yassinefikri) but i have an error when i try to acces to https of http://mywebsite.com/7001/.well-known/mercure
web:
build:
context: .
target: Symfony_PHP
container_name: web_symfony
ports:
- 80:80
- 443:443
- 7002:443
restart: always
volumes:
- ./project/:/var/www/project:delegated
- symfony-var:/var/www/project/var/
- symfony-vendor:/var/www/project/vendor/
networks:
- dev
mercure:
image: dunglas/mercure
container_name: mercure
restart: unless-stopped
environment:
SERVER_NAME: ':80'
MERCURE_PUBLISHER_JWT_KEY: '${MERCURE_PUBLISHER_JWT_KEY}'
MERCURE_SUBSCRIBER_JWT_KEY: '${MERCURE_SUBSCRIBER_JWT_KEY}'
MERCURE_EXTRA_DIRECTIVES: |-
cors_origins "http://mywebsite.com https://mywebsite.com"
anonymous
ports:
- 7001:80
volumes:
- caddy_data:/data
- caddy_config:/config
networks:
- dev
and
const url = new URL('https://{{ app.request.host }}:7001/.well-known/mercure');
.env
MERCURE_URL=http://mercure/.well-known/mercure
MERCURE_PUBLIC_URL=http://localhost:7001/.well-known/mercure
MERCURE_JWT_SECRET=!ChangeMe!
i got this error i try tu subscribe to const url = new URL('https://{{ app.request.host }}:7002/.well-known/mercure');
Access to resource at 'https://mywebsite:7002/.well-known/mercure' from origin 'https://mywebsite.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
and this for const url = new URL('http://{{ app.request.host }}:7002 or 7001 /.well-known/mercure');
Mixed Content: The page at 'https://mywebsite/index' was loaded over HTTPS, but requested an insecure EventSource endpoint 'http://mywebsite:7001/.well-known/mercure'. This request has been blocked; the content must be served over HTTPS.
thank you for the help