Fedora 40
Sponsored Link

Nginx : CGI स्क्रिप्ट का उपयोग करें2024/05/14

 
Nginx पर CGI निष्पादन योग्य वातावरण कॉन्फ़िगर करें।
[1] FastCGI Wrap स्थापित करें और इसके लिए Nginx कॉन्फ़िगर करें।
[root@www ~]#
dnf -y install fcgiwrap
[root@www ~]#
vi /etc/nginx/fcgiwrap.conf
# नया निर्माण
# उदाहरण के लिए, [/cgi-bin] के अंतर्गत CGI सक्षम करें

location /cgi-bin/ {
    gzip off;
    root  /usr/share/nginx;
    fastcgi_pass  unix:/var/run/fcgiwrap.socket;
    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}

[root@www ~]#
mkdir /usr/share/nginx/cgi-bin

[root@www ~]#
chmod 755 /usr/share/nginx/cgi-bin
[root@www ~]#
vi /etc/nginx/conf.d/ssl.conf
# साइट परिभाषा के [server] अनुभाग में सेटिंग्स जोड़ें

server {
        .....
        .....
        include fcgiwrap.conf;
}

[root@www ~]#
systemctl reload nginx

[2] FastCGI Wrap सेवा के लिए Systemd फ़ाइल बनाएं और उन्हें प्रारंभ करें।
[root@www ~]#
vi /usr/lib/systemd/system/fcgiwrap.service
# नया निर्माण

[Unit]
Description=Simple CGI Server
After=nss-user-lookup.target
Requires=fcgiwrap.socket

[Service]
EnvironmentFile=/etc/sysconfig/fcgiwrap
ExecStart=/usr/sbin/fcgiwrap ${DAEMON_OPTS} -c ${DAEMON_PROCS}
User=nginx
Group=nginx

[Install]
Also=fcgiwrap.socket

[root@www ~]#
vi /usr/lib/systemd/system/fcgiwrap.socket
# नया निर्माण

[Unit]
Description=fcgiwrap Socket

[Socket]
ListenStream=/run/fcgiwrap.socket

[Install]
WantedBy=sockets.target

[root@www ~]#
systemctl enable --now fcgiwrap
[3] यदि SELinux सक्षम है, तो नीति बदलें।
[root@www ~]#
vi nginx-server.te
# नया निर्माण

module nginx-server 1.0;

require {
        type unconfined_service_t;
        type var_run_t;
        type httpd_t;
        class sock_file write;
        class unix_stream_socket connectto;
}

#============= httpd_t ==============
allow httpd_t unconfined_service_t:unix_stream_socket connectto;
allow httpd_t var_run_t:sock_file write;

[root@www ~]#
checkmodule -m -M -o nginx-server.mod nginx-server.te

[root@www ~]#
semodule_package --outfile nginx-server.pp --module nginx-server.mod

[root@www ~]#
semodule -i nginx-server.pp

[4] जिस निर्देशिका में आपने CGI निष्पादन योग्य सेट किया है ([/usr/share/nginx/cgi-bin] इस उदाहरण पर) के अंतर्गत एक भाषा (नीचे उदाहरण Python3 है) के साथ एक परीक्षण स्क्रिप्ट बनाएं और CGI सामान्य रूप से काम करता है यह सत्यापित करने के लिए उस तक पहुंचें।
[root@www ~]#
vi /usr/share/nginx/cgi-bin/index.cgi
#!/usr/bin/python3

print("Content-type: text/html\n")
print("<html>\n<body>")
print("<div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\">")
print("CGI Script Test Page")
print("</div>")
print("</body>\n</html>")

[root@www ~]#
chmod 755 /usr/share/nginx/cgi-bin/index.cgi

मिलान सामग्री