Actual combat Nginx and Perl, Java installation and configuration

Source: Internet
Author: User
Tags chmod socket wrapper install perl perl script nginx reverse proxy

Through the previous introduction, you can have a more comprehensive understanding of Nginx: Nginx itself is a static HTTP server and reverse proxy server, it does not support dynamic pages, the so-called Nginx Dynamic program support are implemented through the reverse proxy function. The following nginx to Perl and JSP support is done through the Nginx reverse proxy function. Nginx's support for Perl and JSP may differ in implementation details, but the implementation principle is identical.

The installation of Nginx is no longer described here, which assumes that the Nginx installation path is/usr/local/nginx.

A. Perl (FastCGI) installation

1. Get Wrapper Program

The reader can download the Nginx-fcgi.txt file from the http://www.nginx.eu/nginx-fcgi/, then name it nginx-fcgi.pl and place it in the/usr/local/nginx directory. Nginx-fcgi.pl is a wrapper instance written in Perl script, so the operating system must install Perl programs and related modules.

2. Install the related system support module

You can download the required modules from http://search.cpan.org, and then install them.

(1) Install fcgi module

[Root@localhost opt]# tar zxvf fcgi-0.71.tar.gz

[Root@localhost opt]# CD FCGI-0.71

[Root@localhost fcgi-0.71]# Perl makefile.pl

[Root@localhost fcgi-0.71]# make

[Root@localhost fcgi-0.71]# make install

(2) Install IO module

[Root@localhost opt]# Tar-xvzf io-1.25.tar.gz

[Root@localhost opt]# CD IO-1.25

[Root@localhost io-1.25]# Perl makefile.pl

[Root@localhost io-1.25]# make

[Root@localhost io-1.25]# make install

(3) Install Io::all module

[Root@localhost opt]# Tar-xvzf io-all-0.39.tar.gz

[Root@localhost opt]# CD io-all-0.39

[Root@localhost io-all-0.39]# Perl makefile.pl

[Root@localhost io-all-0.39] #make

[root@localhost io-all-0.39] #make Install

3. Write nginx-fcgi Startup scripts

It's not enough to have a wrapper file, you need a script to create the socket, start the wrapper, and bind the wrapper and the socket, and the following is a shell script to do this series of work.

[Root@localhost root]# more nginx-fcgi

#!/bin/bash

Nginxroot=/usr/local/nginx

Start ()

{

Chown Nobody.root $nginxroot/logs

echo "$nginxroot/nginx-fcgi.pl-l $nginxroot/logs/nginx-fcgi.log-pid $nginxroot/logs/nginx-fcgi.pid-s $nginxroot/ Logs/nginx-fcgi.sock ">> $nginxroot/nginx_fcgi.sh

Chown nobody.nobody $nginxroot/nginx_fcgi.sh

chmod 755 $nginxroot/nginx_fcgi.sh

Sudo-u Nobody $nginxroot/nginx_fcgi.sh

echo "Start nginx-fcgi Done"

}

Stop ()

{

Kill $ (Cat $nginxroot/logs/nginx-fcgi.pid)

RM $nginxroot/logs/nginx-fcgi.pid 2>/dev/null

RM $nginxroot/logs/nginx-fcgi.sock 2>/dev/null

RM $nginxroot/nginx_fcgi.sh 2>/dev/null

echo "Stop nginx-fcgi Done"

}

Case is in

Stop

Stop

;;

Start

Start

;;

Restart)

Stop

Start

;;

*)

echo $ "usage:perl-cgi {Start|stop|restart}"

Exit 1

Esac

In nginx-fcgi, the variable nginxroot specifies the Nginx installation directory, Nginx-fcgi.sock is the generated file sock, and nobody is the user who runs the nginx_fcgi process, which is consistent with the user who is running Nginx.

After you configure the script, place the file in the/usr/local/nginx directory, and then manage the nginx-fcgi process in the following manner.

[root@localhost Root] #chmod 755/usr/local/nginx/nginx-fcgi.pl

[root@localhost Root] #chmod 755/usr/local/nginx/nginx-fcgi

[Root@localhost root]#/usr/local/nginx/nginx-fcgi Start|stop|restart

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.