how to configure nginx as proxy with apache

General support questions
Post Reply
rootrookie
Posts: 5
Joined: 2015/07/03 16:51:04
Location: The Netherlands
Contact:

how to configure nginx as proxy with apache

Post by rootrookie » 2017/02/01 23:43:41

This comes up whenever you search the forum but alot times the "how to..." is filled by people from vendors that have their respective custom distro's of CentOS which have tutorials that are closely related to their specific webhosting platform.

Can anyone point me to a source where I as someone who is building his VPS CentOS 6.8 webserver from scratch and how to configure nginx as proxy and just setup a hosting account via the CentOS command line instruction set without any bells or whistles from any third party ?

Greatly appreciated

aks
Posts: 3073
Joined: 2014/09/20 11:22:14

Re: how to configure nginx as proxy with apache

Post by aks » 2017/02/02 17:22:18

Quite simply, for the proxy part, all I did was:

1) Put my location block in (for example location /app) and then proxy_pass that to (example: https://10.1.10.1/app).
2) Include a "common" proxy config. In there you can specify the stuff you want for every proxy entry.

Example:

location /app {
proxy_pass https://10.1.10.1/app;
include /etc/nginx/conf.d/proxy_common.conf;
}
Then for the proxy common:
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Ssl on;
proxy_redirect off;
proxy_connect_timeout 10;
proxy_send_timeout 20;
proxy_read_timeout 30;
proxy_buffer_size 4k;
proxy_buffers 16 4k;
proxy_busy_buffers_size 16k;
client_max_body_size 10m;
client_body_buffer_size 128k;
client_body_timeout 45;
proxy_ssl_session_reuse on;
etc ....

You can also "map" upstreams with the $upstream. So you can do something like:

map $upstream_http_cache_control $custom_cache_control {
# Set the $custom_cache_control variable with the original response header from the upstream server if it consists of at least one character (. is a regex)
"~." $upstream_http_cache_control;
# Otherwise set it with this value to x seconds.
default max-age=1;
}

Post Reply