Create a proxy to another port

youds

Verified User
Joined
Jul 11, 2008
Messages
493
Location
Lancashire, UK
Helllo

I can access http://ip.add.re.ss:5001 just fine, I want to access it via domain name and port 80/443, what would I use in nginx.conf? I currently have this entered into CUSTOM3.

Code:
location /knowledgebase
{  
        proxy_buffering off;
        proxy_pass http:///ip.add.re.ss:5001;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Client-IP      $remote_addr;
        proxy_set_header X-Accel-Internal /nginx_static_files;
        proxy_hide_header Upgrade;
}

What am I doing wrong?
 
Last edited:
if your static file is on your proxy too, you don't need this line.
Code:
proxy_set_header X-Accel-Internal /nginx_static_files;

your code are all correct. the problem is on your firewall, you need to open the port outgoing "5001".
, if your application not on same server.
 
OK so adding 5001 to csf.conf didn't fix things.

Here is the full config:
Code:
server
{
    listen serverip:80;
    server_name community.myproject.com www.community.myproject.com;
    access_log /var/log/nginx/domains/community.myproject.com.log;
    access_log /var/log/nginx/domains/community.myproject.com.bytes bytes;
    error_log /var/log/nginx/domains/community.myproject.com.error.log;
    root "/home/myopen/domains/community.myproject.com/public_html";
    index index.php index.html index.htm;
    if ($http_x_forwarded_proto != 'https') {
        return 301 https://$host$request_uri;
    }
    # Mail auto configuration (Thunderbird)
    location = "/.well-known/autoconfig/mail/config-v1.1.xml" {
        proxy_pass http://unix:/usr/local/directadmin/shared/internal.sock;
        proxy_set_header X-Forwarded-For  $remote_addr;
        proxy_set_header X-Forwarded-Host $host;
    }
    location /
    {
        # access_log off;
        proxy_buffering off;
        proxy_pass http://serverip:8080;
        proxy_set_header X-Client-IP      $remote_addr;
        proxy_set_header X-Accel-Internal /nginx_static_files;
        proxy_set_header Host             $host;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_hide_header Upgrade;
    }
    location /nginx_static_files/
    {
        # access_log  /var/log/nginx/access_log_proxy;
        alias       "/home/myopen/domains/community.myproject.com/public_html/";
        internal;
    }
location /knowledgebase
{  
        proxy_buffering off;
        proxy_pass http://serverip:5001;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Client-IP      $remote_addr;
        proxy_hide_header Upgrade;
}
    include /etc/nginx/webapps.conf;
}
server
{
    listen serverip:443 ssl;
    http2 on;
    server_name community.myproject.com www.community.myproject.com;
    access_log /var/log/nginx/domains/community.myproject.com.log;
    access_log /var/log/nginx/domains/community.myproject.com.bytes bytes;
    error_log /var/log/nginx/domains/community.myproject.com.error.log;
    root "/home/myopen/domains/community.myproject.com/private_html";
    index index.php index.html index.htm;
    ssl_certificate /usr/local/directadmin/data/users/myopen/domains/community.myproject.com.cert.combined;
    ssl_certificate_key /usr/local/directadmin/data/users/myopen/domains/community.myproject.com.key;
    # Mail auto configuration (Thunderbird)
    location = "/.well-known/autoconfig/mail/config-v1.1.xml" {
        proxy_pass http://unix:/usr/local/directadmin/shared/internal.sock;
        proxy_set_header X-Forwarded-For  $remote_addr;
        proxy_set_header X-Forwarded-Host $host;
    }
    location /
    {
        # access_log off;
        proxy_buffering off;
        proxy_pass https://serverip:8081;
        proxy_set_header X-Client-IP      $remote_addr;
        proxy_set_header X-Accel-Internal /nginx_static_files;
        proxy_set_header Host             $host;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_hide_header Upgrade;
    }
    location /nginx_static_files/
    {
        # access_log  /var/log/nginx/access_log_proxy;
        alias       "/home/myopen/domains/community.myproject.com/private_html/";
        internal;
    }
location /knowledgebase
{  
        proxy_buffering off;
        proxy_pass http://serverip:5001;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Client-IP      $remote_addr;
        proxy_hide_header Upgrade;
}
    include /etc/nginx/webapps.ssl.conf;
}
 
The service doesn't load in the same way as if I visit serverip:5001 directly. No errors are given.
 
Where would you typically get an error? There is no error at point of connection and the browser just doesn’t load. I looked in /var/log/nginx/error_log nothing there.
 
I'm out of ideas and have no time to test your setup and replicate it on my end. I hope somebody else will help you more.
 
Back
Top