2010年12月15日 星期三

Nginx Web伺服器(ASP.NET)

1.概述
使nginx Web server支援ASP.NET服務
Platform : CentOS5 for x86
2. 確定PATH環境變數
# echo $PATH
PATH路徑如只有/usr/bin:/usr/sbin , 請加入以下路徑 
# vi /etc/profile
內容如下 PATH=/usr/lib/qt3.3/bin:/usr/kerberos/sbin:/usr/kerberos/
bin:/usr/lib/ccache:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
export PATH

LD_LIBRARY_PATH=/lib:/usr/local/lib:/usr/lib
export LD_LIBRARY_PATH

[root@Nginx-Web-Svr ~]# export PKG_CONFIG_PATH=/usr/lib/pkgconfig/:/usr/lib/

3. 下載所需套件
[root@Nginx-Web-Svr ~]# yum install -y
httpd build-essential gcc bzip bison pkgconfig glib-devel \
glib2-devel httpd-devel libpng-devel libX11-devel freetype fontconfig \
pango-devel ruby ruby-rdoc gtkhtml38-devel wget

4. 下載原始程式
網址

原始檔名:
mono-2.6.7.tar.bz2
xsp-2.6.5.tar.bz2
nginx-0.8.53.tar.gz

5. 編譯/安裝Mono
[root@Nginx-Web-Svr ~]# tar jxvf mono-2.6.7.tar.bz2
[root@nginx-web-svr ]# cd mono-2.6.7
[root@nginx-web-svr mono-2.6.7]# ./configure --prefix=/usr
[root@nginx-web-svr mono-2.6.7]# make && make install
[root@nginx-web-svr mono-2.6.7]# cd ..

[root@Nginx-Web-Svr ~]# tar jxvf xsp-2.6.5.tar.bz2
[root@Nginx-Web-Svr ~]# cd xsp-2.6.5
[root@Nginx-Web-Svr xsp-2.6.5]# ./configure --prefix=/usr
[root@Nginx-Web-Svr xsp-2.6.5]# make && make install
[root@Nginx-Web-Svr xsp-2.6.5]#cd ..

6. 編譯/安裝Nginx
[root@nginx-web-svr ~]# groupadd www
[root@nginx-web-svr ~]# useradd -g www -s /sbin/nologin www
[root@nginx-web-svr ~]# tar zxvf nginx-0.8.53.tar.gz
[root@nginx-web-svr ~]# cd nginx-0.8.53
[root@nginx-web-svr nginx-0.8.53]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_flv_module
[root@nginx-web-svr nginx-0.8.53]# make && make install

6.1啟動fastcgi-mono-server2
[root@Nginx-Web-Svr /]# /usr/bin/fastcgi-mono-server2 /applications=/:/usr/local/nginx/html/ /socket=tcp:127.0.0.1:9000 &
:/application=i
/ 表示url root
:/usr/local/nginx/html 表示網頁存放位置
/socket 表示listen port

6.2查看port 9000
[root@Nginx-Web-Svr conf]# netstat -na |grep -w 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN


6.3 Nginx設定檔
user www;
worker_processes 4;
error_log logs/error.log crit;
pid logs/nginx.pid;


events {
use epoll;
worker_connections 51200;
}


http {
include mime.types;
default_type application/octet-stream;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;

tcp_nopush on;
tcp_nodelay on;
sendfile on;

keepalive_timeout 60;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;


server {
listen 80;
server_name 192.168.1.10;
index index.html index.htm index.aspx index.asp default.aspx default.asp Default.aspx Default.asp;
root /usr/local/nginx/html;

location ~ \.(aspx|asp|asmx|ashx|asax|ascx|soap|rem|axd|cs|config|dll)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv)$
{
expires 30d;
}
location ~ .*\.(css|js)$
{
expires 1h;
}

access_log off;

# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
6.4 啟動Nginx
[root@Nginx-Web-Svr /]# ulimit –SHn 65535
[root@Nginx-Web-Svr /]# /usr/local/nginx/sbin/nginx
root@Nginx-Web-Svr /]# netstat –na |grep –w 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN

6.5 自動啟動Nginx
[root@Nginx-Web-Svr /]# vi /etc/rc.local
ulimit –SHn 65535
/usr/local/nginx/sbin/nginx

6.6 優化Linux Kernel參數
[root@Nginx-Web-Svr /]# vi /etc/sysctl.conf
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768

net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800

#net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024 65535

使設定馬上生效
[root@Nginx-Web-Svr /]# /sbin/sysctl –p

6.7 Reload nginx.conf配置檔
[root@Nginx-Web-Svr /]# /usr/local/nginx/sbin/nginx –s reload

6.8 定時切割Nginx log file script
[root@Nginx-Web-Svr /]# vi /usr/local/nginx/sbin/cut_nginx_log.sh
#!/bin/bash
# This script run at 00:00

# The Nginx logs path
logs_path=”/usr/local/nginx/logs/”

mkdir –p ${logs_path}$(date –d “yesterday” +”%Y”)/$(date –d “yesterday” +”%m”)/
mv ${logs_path}access.log ${logs_path}$(date –d “yesterday” +”%Y”)/$(date –d “yesterday” +”%m”)/access_$(date –d “yesterday” +”%Y%m%d”).log
kill –USR1 `cat /usr/local/nginx/nginx.pid`

6.9 設定crontab
00 00 * * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh

6.10 測試Nginx網頁
下載測試asp網頁
aspnetsysinfo-vvevision_23.zip解壓至nginx web server 目錄內即可
如看到如下畫面表示有支援asp .net!!
參考資料

沒有留言:

張貼留言