Score:2

How to handle proxy call in apache

cn flag

I have a reverse proxy setup as follows in Apache:

Server A with address www.proxyserver.com/graphql is the reverse proxy server.

It maps to: Server B with address example.com

This kind works properly in develop environment.

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 [email protected]
    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"
</VirtualHost>

and this is server A configuration

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerAdmin [email protected]
        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
        </Proxy>
        <FilesMatch \.(php|phar)$>
            SetHandler "proxy:fcgi://proxyserver.com"
        </FilesMatch>

        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
    </VirtualHost>
</IfModule>
cn flag
I thought the `Proxy...` commands were for the proxy server (Server A). Server B should not even know it's behind a proxy. That being said, there may be a need to _remember_ some host names for things to work as expected. You should also show us the settings of Server A.
Ming Hieu avatar
cn flag
@AlexisWilke I've just edited my post. please check above
cn flag
Hmmm... does the client connect to server A or server B?
Ming Hieu avatar
cn flag
server B is client (reactjs) and server A is backend (php). so the client connect to server A
cn flag
Ah, I see that you are using a Unix socket (`unix:/var/opt/remi/php73/run/php-fpm/php73-fpm.sock`). In your development, are you running server A & B on the same computer and in live mode they are separate computers? That could be the issue. I've actually never used a Unix socket for proxy-ing services.
Ming Hieu avatar
cn flag
no, they are on same computer. the configuration part for unix socket is superfluous, I forgot to remove it
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.