Master OpenResty Reverse Proxy: High‑Performance Static & Dynamic Configurations
This guide explains how to set up high‑performance reverse proxy with OpenResty, covering both static resource routing and dynamic API forwarding, complete with Nginx configuration files for documentation, front‑end, Java and PHP back‑ends, and testing steps.
Reverse proxy forwards client requests to other servers, making the proxy appear as the original source; users are unaware of the redirection. The article uses domain‑level examples to illustrate static and dynamic proxy setups with OpenResty.
Static Proxy
Static proxy maps domain names to specific file system paths. Two examples are provided:
Documentation site – requests to docs.tinywan.com are served from /usr/share/nginx/html/docs.
Front‑end mall – requests to mall.tinywan.com are served from /usr/share/nginx/html/mall.
server {
listen 80;
server_name docs.tinywan.com; # modify domain
location / {
root /usr/share/nginx/html/docs; # proxy to docs folder
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}After reloading Nginx, docs.tinywan.com serves the documentation site.
server {
listen 80;
server_name mall.tinywan.com; # modify domain
location / {
root /usr/share/nginx/html/mall; # proxy to mall folder
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}After reloading Nginx, mall.tinywan.com serves the front‑end project.
Dynamic Proxy
Dynamic proxy forwards requests to another service, such as an API backend. Two language‑specific examples are shown.
Java API Proxy
server {
listen 80;
server_name api.tinywan.com; # modify domain
location / {
proxy_pass http://120.27.63.9:8080; # target service address
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}After restarting Nginx, accessing api.tinywan.com/swagger-ui.html displays the API documentation of the mall-admin service.
PHP API Proxy
server {
listen 80;
server_name api.tinywan.com; # modify domain
set $root_path /home/www/web/api.tinywan.com/public; # project path
root $root_path;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm.sock; # socket‑based TCP proxy
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
}
}Reloading Nginx enables PHP request handling through the proxy.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
