P
P
PoorFrog2020-08-12 12:05:35
Nginx
PoorFrog, 2020-08-12 12:05:35

How to set up forwarding from Apache to Nginx?

There are two Apache and Nginx servers running on the remote host. The main server is Apache. It redirects to Nginx.
Apache configuration:

<VirtualHost my_host:80 >
        ServerName example.com
        ServerAlias www.example.com
        ProxyPreserveHost On
        ProxyPass               /       http://localhost:81/
        ProxyPassReverse        /       http://localhost:81/
</VirtualHost>

Nginx configuration:
server {
        listen       81 default_server;
        listen       [::]:81 default_server;
        server_name  example.com www.example.com;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }

        location / {
                proxy_pass http://127.0.0.1:8080;
                proxy_set_header X-Forwarded-Host $server_name;
                proxy_set_header X-Real-IP $remote_addr;
                add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
                add_header Access-Control-Allow-Origin *;
        }
    }

When you type example.com in the address bar, everything is fine. But when you go to the site from the search results, my_host:81 is displayed in the address bar instead of the domain name. How to overcome it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question