I have a reverse proxy setup as follows in Apache:

Server A with address www.proxyserver.com/graphql is the reverse proxy server. (magento - php)

It maps to: Server B with address example.com (reactjs)

This kind works properly while running in debug mode (npm run start).

For e.g: when server call a request /graphql?query1=query1&query2=query2 then it redirects to https://proxyserver.com/graphql?query1=query1&query2=query2

But in apache, it doesn't work. It calls http://example.com/graphql?query1=query1&query2=query2

How do I fix this?

My reverse proxy is configured as follow on Server B (www.example.com):

<VirtualHost *:80>
    ServerAdmin admin@example.com
    DocumentRoot /var/www/example.com/build
    ServerName example.com
    ServerAlias www.example.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    ProxyPreserveHost On
    ProxyPass "/graphql" "https://proxyserver.com/graphql"
    ProxyPassReverse "/graphql" "https://proxyserver.com/graphql"

and this is server A configuration

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerAdmin admin@arrowhitech.com
        DocumentRoot /etc/pub
        ServerName proxyserver.com
        ErrorLog logs/cezanno-error_log
        LimitRequestBody 104857600
        <Proxy "unix:/var/opt/remi/php73/run/php-fpm/php73-fpm.sock|fcgi://proxyserver.com">
            ProxySet timeout=100
        <FilesMatch \.(php|phar)$>
            SetHandler "proxy:fcgi://proxyserver.com"

        SSLCertificateFile /path/to/cert/directory/cert.pem
        SSLCertificateKeyFile /path/to/cert/directory/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateChainFile /path/to/cert/directory/chain.pem
  • You say that, "This kind works properly in develop environment" but then you you say that, "in apache, it doesn't work". Surely development and production environments are both using Apache?
    – roaima
    Jul 21 at 8:12
  • no, in develop environment, I just simply use npm run start to run, not use apache or any web servers to run it
    – Ming Hieu
    Jul 21 at 8:45
  • The way you've written "This kind works properly in develop environment." implies that what you have described to us works in the development environment but does not work in production. If your environments are different please take the time to explain this in your question
    – roaima
    Jul 21 at 8:52
  • I've just edited the original post. I mean develop environment is using command npm run start to run it
    – Ming Hieu
    Jul 21 at 9:17
  • When you say "calls" do you mean proxies through to? Can you be clear on what you expect it to do? IE if you point curl at your server A, you aren't expecting a redirect but a direct response proxied from server B? Jul 21 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.