简体   繁体   中英

Nginx reverse proxy to Gogs

i am trying to implement a nginx server as reverse proxy for accessing my Gogs instance. Reason is i need to access my services from work, where all but standard ports are blocked. To avoid port conflicts on my server, most serves are running on ports >1000 (and, for that matter, Gogs too, on default 3000). So i created my own vhost config to redirect to Gogs. I get the plain html site, but errors showing errors on loading images and scripts. It seems as if the Gogs itself redirect the clients to multiple subressources, for example /js, /img, /asset and /user. I then added the /js and /img paths as location to my nginx config and got the site running. However, this seems to quite a lot of work, keeping all those paths tracked and configured. Is there a way for me to serve those paths to the client via nginx without having to configure them one by one?

The Gogs and nginx instance are running on the same server, the redirect is configured via ip, no loopback like localhost or 127.0.0.1 used, even though i tried that without success.

Thanks in advance for your help and find my config below. RMG PS: I checked different tutorials and questions, including this stackoverflow question

 server { listen 80 default_server; server_name devsrv; #this redirect to another server on port 80 works fine location /nextcloud { proxy_pass http://OTHERIP/nextcloud; } location /gogs/ { proxy_set_header X-Real-IP $remote_addr; proxy_pass http://LOCALIP:3000/; } # gogs script location location /js { proxy_pass http://LOCALIP:3000/js; } # gogs image location location /img { proxy_pass http://LOCALIP:3000/img; } } 

server {
        listen 80 default_server;
        server_name devsrv;

        #this redirect to another server on port 80 works fine
        location /nextcloud {
                proxy_pass http://OTHERIP/nextcloud;
        }

        location /gogs/ {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_pass http://LOCALIP:3000/;
        }
        location / {
                proxy_pass http://LOCALIP:3000$request_uri;
        }


}

Set all the specific url that need to be handled with special params (X-Real-IP on /gogs or/nextcloud to other ip) and send all the others to gogip with $request_uri.

/js? LOCALIP:3000/js

/img ? LOCALIP:3000/img

Everything will go to it's own path that arrived.

If you want to send only the connections that come from gogs to the REALIP (I will suppose those redirects sent from gogs come from the REALIP ), you can make another bracket set, so you can:

server {
        listen REALIP:80 default_server;
        server_name devsrv;

        #this redirect to another server on port 80 works fine
        location / {
                proxy_pass http://REALIP:3000$request_uri;
        }
}

Hope I helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM