G
G
germisten2021-01-13 02:41:05
Nginx
germisten, 2021-01-13 02:41:05

How to correctly register a config for a directory with a CGI script?

There is a /srv/http directory:

├── test.db
├── test.sh
└── styles
    └── style.css


test.sh, of course, makes up an html page that reads the stylesheet styles/style.css. The script must be executed when called, for example, localhost . Also, the script must read the address bar parameters and process them. So localhost/shit , localhost/fuck , localhost/cringe nginx should be passed to the script, while localhost/styles should be treated as a directory so that html can read the styles properly.

Now I googled different things and combined them into one:

server {
    listen 80;
    root /srv/http;
    index test.sh;
    server_name localhost;
    charset utf-8;
    location /styles/ {
      location ~ \.(?:jpg|jpeg|gif|png|ico|css|js)$ {
        log_not_found off;
        expires 90d;
        gzip on;
        gzip_types text/plain text/css application/x-javascript text/javascript;
        gzip_static on;
        gzip_http_version 1.1;
        gzip_comp_level 8;
      }
      return 404;
    }
    location / {
      fastcgi_split_path_info ^(.+?\.sh)(/.*)$;
      fastcgi_pass  unix:/run/fcgiwrap.sock;
      fastcgi_index test.sh;
      include fastcgi_params;
    }
}


The main page works fine, but the rest give a 403 error. In the file system, this is not possible - I even put 777 on the entire directory. There can be no script errors either, because it was possible to run on Apache. Please tell me where I made a mistake.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2021-01-13
@Lynn

nginx basically doesn't know CGI.
So you need something that will work on the fastcgi/http protocol and run the script. For example https://www.nginx.com/resources/wiki/start/topics/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question