How do I set up a reverse proxy with nginx?
-
I have set up my nginx config as recommended at http://codex.wordpress.org/Nginx and it all works fine. Now, I want to add a reverse proxy so that mysite.com/logs/ points to port 8000 on another local machine (192.168.0.105:8000). In my attempt to accomplish this, I added the following code to the bottom of /etc/nginx/global/wordpress.conf :
location /logs/ { proxy_pass http://192.168.0.105:8000; proxy_redirect default; proxy_set_header Host $http_host; }The desired effect, however, is not accomplished. Pointing a browser to mysite.com/logs/ now takes me to a wordpress 404 page. Strangely, I first get the popup from 192.168.0.105:8000 asking for my kibana credentials, but upon entering them I am redirected to the 404 page. I believe my reverse proxy is being negated somewhere else in the config file, I just don’t know nginx well enough to figure out how to fix this. Any thoughts? Below is my nginx config:
**********nginx.conf
# Generic startup file. user nginx nginx; #usually equal to number of CPUs you have. run command "grep processor /proc/cpuinfo | wc -l" to find it worker_processes 2; error_log /www/mysite.com/logs/error.log; pid /var/run/nginx.pid; # Keeps the logs free of messages about not being able to bind(). #daemon off; events { worker_connections 1024; } http { # rewrite_log on; include mime.types; default_type application/octet-stream; access_log /www/mysite.com/logs/access.log; sendfile on; # tcp_nopush on; keepalive_timeout 3; # tcp_nodelay on; # gzip on; #php max upload limit cannot be larger than this client_max_body_size 13m; index index.php index.html index.htm; # Upstream to abstract backend connection(s) for PHP. upstream php { #this should match value of "listen" directive in php-fpm pool server unix:/var/run/php-fpm/www.sock; server 127.0.0.1:9000; } include sites-enabled/*; include conf.d/*.conf; }**********/sites-available/mysite.conf
# Redirect everything to the main site. We use a separate server statement and NOT an if statement - see http://wiki.nginx.org/IfIsEvil server { server_name _; rewrite ^ $scheme://mysite.com$request_uri redirect; } server { server_name mysite.com; root /www/mysite.com/public; index index.php; include global/restrictions.conf; # Additional rules go here. # Only include one of the files below. include global/wordpress.conf; # include global/wordpress-ms-subdir.conf; # include global/wordpress-ms-subdomain.conf; }**********/global/wordpress.conf
# WordPress single site rules. # Designed to be included in any server {} block. # This order might seem weird - this is attempted to match last if rules below fail. # http://wiki.nginx.org/HttpCoreModule location / { try_files $uri $uri/ /index.php?$args; } # Add trailing slash to */wp-admin requests. rewrite /wp-admin$ $scheme://$host$uri/ permanent; # Directives to send expires headers and turn off 404 error logging. location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { access_log off; log_not_found off; expires max; } # Uncomment one of the lines below for the appropriate caching plugin (if used). #include global/wordpress-wp-super-cache.conf; #include global/wordpress-w3-total-cache.conf; # Pass all .php files onto a php-fpm/php-fcgi server. location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; if (!-f $document_root$fastcgi_script_name) { return 404; } # This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default) include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; # fastcgi_intercept_errors on; fastcgi_pass php; } location /logs/ { proxy_pass http://192.168.0.105:8000; proxy_redirect default; proxy_set_header Host $http_host; }
The topic ‘How do I set up a reverse proxy with nginx?’ is closed to new replies.