Server Deployment - nginx

本文介绍了如何使用Nginx配置文件实现对Perl CGI脚本的支持,并通过upstream指令负载均衡到多个本地服务。同时展示了如何监控Nginx状态及配置Perl CGI参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Server Deployment - nginx

1. proxy configuration
The configuration file is /etc/nginx/nginx.conf, but I can change another file:
>vi /etc/nginx/conf.d/easymarket.conf
configuration files:
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

upstream easy {
ip_hash;
server localhost:8083;
server localhost:8084;
server localhost:8085;
}

server {
listen 83;
server_name localhost;

charset utf-8;

access_log logs/host.access.log main;

location /nginxstatus {
stub_status on; #nginx status watch
access_log off;
}

location / {
proxy_pass http://easy;
proxy_set_header X-Real-IP $remote_addr;
}

#location / {
# root html;
# index index.html index.htm;
#}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

we can see the status with URL
http://localhost:83/nginxstatus

2. config the perl cgi
The configuration file easymarket.conf will be as follow:
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

upstream easy {
ip_hash;
server localhost:8083;
server localhost:8084;
server localhost:8085;
}

server {
listen 83;
server_name localhost;

charset utf-8;

access_log logs/host.access.log main;
root /var/www;

location /nginxstatus {
stub_status on; #nginx status watch
access_log off;
}

location ~\.pl$ {
gzip off;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_index index.pl;
fastcgi_param SCRIPT_FILENAME /var/www/easyperl$fastcgi_script_name;
}


location /easymarket {
proxy_pass http://easy;
proxy_set_header X-Real-IP $remote_addr;
}

#location / {
# root html;
# index index.html index.htm;
#}

#error_page 404 /404.html;


# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

Test the Perl page:
http://localhost:83/easyperl/Action.pl
http://localhost:83/easyperl/All.pl

references:
http://hi.baidu.com/luohuazju/blog/item/8baa8f1738303c0a4b90a771.html
http://hi.baidu.com/luohuazju/blog/item/f7880d822e5f12b86c811902.html
http://library.linode.com/web-servers/nginx/perl-fastcgi/ubuntu-11.04-natty
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值