Score:0

nginx proxy to public websites

ng flag

I'm trying to configure a proxy to public websites (origin) with the addition of my script to the head element of the HTML. The way I can access https://proxy.mywebsite.info/?script=www.myscript.com/a.js&origin=google.com and get the origin website with my script injected.

The injection part works fine but somehow any public website which is loaded shows me errors like I'm doing the proxying wrong. Out of ideas after hours of trying different nginx.conf settings.

proxy.mywebsite.info points to my machine 127.0.0.1.

The error I'm getting from nginx

[error] 2203#2203: *272 invalid URL prefix in "https://", client: 127.0.0.1, server: proxy.mywebsite.info, request: "GET /favicon.ico HTTP/1.1", host: "proxy.mywebsite.info"

worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
}

http {
        server {
            listen 443 ssl;
            server_name proxy.mywebsite.info;
            ssl_certificate     /etc/ssl/certs/proxy.mywebsite.info.crt;
            ssl_certificate_key /etc/ssl/private/proxy.mywebsite.info.key;
            keepalive_timeout   70;
            proxy_ssl_server_name on;
            proxy_ssl_session_reuse off;
            ssl_protocols       TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
            ssl_ciphers         HIGH:!aNULL:!MD5;
            root /var/www/html;
            index index.html;
            access_log /tmp/access.log;
            error_log /tmp/error.log;
            location / {
                resolver 8.8.8.8;
                proxy_pass https://$arg_origin;
                proxy_read_timeout 10;
                proxy_set_header Host $host;
                proxy_set_header Accept-Encoding "";
                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header Connection "Keep-Alive";
                proxy_set_header Proxy-Connection "Keep-Alive";
                proxy_ssl_name $host;
                proxy_ssl_server_name on;
                proxy_ssl_session_reuse off;
                sub_filter '<head>' '<head><script src="https://$arg_script"></script>';
                sub_filter_once on;
           }
       }
}

Any help is well appreciated.

djdomi avatar
za flag
Please decide, either use `root` or `proxy_pass` however, I don't see a legit use for this kind? And remind that temp will not log rotated
ng flag
@djdomi, the legit use is to embed javascript file when testing mobile applications which have no extensions to inject javascript during runtime. Moreover, root is ignored because of proxy on /.
djdomi avatar
za flag
myself would just use a php proxy to test that due it will be working the same way I think
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.