• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question Using nginx to proxy a server other than Apache

TurabG

Basic Pleskian
Hi.

I am using an application server on port 3065 and when I get to http://host:3065 it works. I would like to use nginx to proxy this server so it could serve that app.

The application suggests the following settings for nginx;

Code:
upstream backend {
   server 127.0.0.1:8065;
}

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path=off;

server {
   listen 80;
   server_name    example.com;

   location /api/v3/users/websocket {
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      client_max_body_size 50M;
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Frame-Options SAMEORIGIN;
      proxy_buffers 256 16k;
      proxy_buffer_size 16k;
      proxy_read_timeout 600s;
      proxy_pass http://backend;
   }

   location / {
      client_max_body_size 50M;
      proxy_set_header Connection "";
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Frame-Options SAMEORIGIN;
      proxy_buffers 256 16k;
      proxy_buffer_size 16k;
      proxy_read_timeout 600s;
      proxy_cache mattermost_cache;
      proxy_cache_revalidate on;
      proxy_cache_min_uses 2;
      proxy_cache_use_stale timeout;
      proxy_cache_lock on;
      proxy_pass http://backend;
   }
}

As you would know, "server", "backend" and "location" directives are not allowed in Additional nginx Directives section. And you would also know that sites-enabled directory is not present in Plesk installations.

So how to configure these kind of settings per domain for nginx?

Note; "Proxy mode" is disabled as per its definition suggests; "Turn off to stop using Apache." So I turned it off to use only nginx on that domain.
 
You only need to create files in /etc/nginx/conf.d/

I have several of them.
Name them zz090_*.conf so they will be executed after the other stuff. If you want it to to execute sooner then decrease it in alphabetic order.
A restart of nginx will include them.

I'm using it to secure services running on localhost with http and even on off-site webservers.

I'm also using it for autoprovisioning email clients.

Here an example where I use it to proxy rslsync.

# cat /etc/nginx/conf.d/zz090_rslsync.conf
Code:
server {
    listen 115.24.200.20:443 ssl;
    server_name rslsync.wolf.com;

    ssl_certificate             /root/.ssh/2017/2017.wildcard.wolf.com.pem;
    ssl_certificate_key         /root/.ssh/2017/2017.wildcard.wolf.com.key;

    ssl_stapling on;
    ssl_stapling_verify on;

    ssl_session_timeout         5m;

    ssl_protocols               TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers                 HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;
    ssl_dhparam                 /etc/nginx/ssl/dhparams.pem;

    client_max_body_size 128m;

    location / {
        proxy_pass http://127.0.0.1:57889;        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
 
Last edited:
Placing "server" directive in any configuration file always fired a compilation error saying that server directive is not allowed to be used there; because it was used elsewhere once.

I tried this in vhost conf files before. I will give it a try putting it in conf.d but I don't understand how would it be any different.
 
You can't use that server entry anywhere else, but rslsync.wolf.com is NOT configured within Plesk.
I've been doing this for several years....
The config file I gave you is from a live server (a bit patched to obscure its origin)
 
So you say if I want to proxy any other servers that are not present in Plesk; I wouldn't create a subdomain in Plesk; rather I would place it's configuration file in conf.d?
 
Yes...
Why would you place that server/service in Plesk anyhow?
It already has its own webserver.

rslsync.wolf.com is not known to the Plesk server on which it is running.
 
Yes it has it's own server running on a different port; but the server itself recommended to be proxied by nginx for security. It also needed to have port 80 be forwarded so I could browse it without having to type the port number.

Plus; I also run some PHP software that needs these directives set to get it work on nginx/PHP-FPM. I mean not for proxy; for directly running the application on nginx neglecting Apache.
 
But did you try my example with this instead??
It is AFAIK exactly what you need.
Code:
   location / {
       proxy_pass http://127.0.0.1:8065;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   }
 
Back
Top