歡迎您光臨本站 註冊首頁

Apache 轉移到 Nginx 筆記!

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

Apache 轉移到 Nginx 筆記!

RedHat AS4 U5 +nginx-0.7.30 + php-5.2.8 + mysql-5.1.30 +Zend-3.3.3 + vsftpd-2.0.5

作者:Linuxsun
出處:LSUN技術論壇 http://bbs.linuxsun.cn
目標:運用低的硬體配置做最高效的服務平台!
本次實驗:
P4 2.8 512M內存 80G硬碟 10M獨享 nginx虛擬機數量5個以上 vsftpd二個虛擬用戶 域名:
http://bbs.linuxsun.cn
基本軟體的安裝,文章可以看:http://bbs.linuxsun.cn/search.php?
searchid=6&;orderby=lastpost&ascdesc=desc&searchsubmit=yes&page=2
這裡主要說明一些出錯的解決方法以及給出源配置文件。
基本的軟體都運行起來了:
======================================================
# netstat -na |grep LISTEN
tcp        0      0 0.0.0.0:903                 0.0.0.0:*                   LISTEN   
  
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN   
  
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN   
  
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN   
  
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN   
  
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN   
  
tcp        0      0 221.5.41.5:53               0.0.0.0:*                   LISTEN   
  
tcp        0      0 127.0.0.1:53                0.0.0.0:*                   LISTEN   
  
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN   
  
tcp        0      0 127.0.0.1:953               0.0.0.0:*                   LISTEN   
  
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN   
  
tcp        0      0 :::22                       :::*                        LISTEN   
  
======================================================
Nginx.conf
-------------------------------------------------------------
user  www linuxsun;
worker_processes 10;
pid /var/log/nginx.pid;
error_log  /dev/null;
worker_rlimit_nofile 51200;
events
{
       use epoll;
       #maxclient = worker_processes * worker_connections / cpu_number
       worker_connections 51200;
}
http
{
       include       /usr/local/nginx/conf/mime.types;
       default_type  application/octet-stream;
       charset  gb2312;
       log_format  main  '$remote_addr - $remote_user [$time_local] $request '
                         '"$status" $body_bytes_sent "$http_referer" '
                         '"$http_user_agent" "$http_x_forwarded_for"';
       access_log  /dev/null;
       server_names_hash_bucket_size 128;
       client_header_buffer_size 32k;
       large_client_header_buffers 4 32k;
       ignore_invalid_headers   on;
       recursive_error_pages    on;
       server_name_in_redirect off;
       sendfile                 on;
       keepalive_timeout 60;
       tcp_nopush  on;
       tcp_nodelay on;
       fastcgi_connect_timeout 300;
       fastcgi_send_timeout 300;
       fastcgi_read_timeout 300;
       fastcgi_buffer_size 128k;
       fastcgi_buffers 4 128k;
       fastcgi_busy_buffers_size 128k;
       fastcgi_temp_file_write_size 128k;
       fastcgi_intercept_errors on;
       client_max_body_size       50m;
       client_body_buffer_size    256k;
       gzip on;
       gzip_min_length  0;
       gzip_buffers     16 8k;
       gzip_http_version 1.0;
       gzip_comp_level 9;
       gzip_types       text/plain text/css image/x-icon image/png;
       gzip_vary on;
       proxy_temp_path            /dev/shm/proxy_temp;
       fastcgi_temp_path          /dev/shm/fastcgi_temp;
       client_body_temp_path      /dev/shm/client_body_temp;
        #www.linuxsun.cn
        include          /usr/local/nginx/conf/vhosts/linuxsun.conf;
}
-------------------------------------------------------------
/usr/local/nginx/conf/vhosts/linuxsun.conf
============================================
server {
listen       80;
server_name  bbs.linuxsun.cn;
root /www/bbs;
location / {
index index.html index.htm index.php;
root /www/bbs;
rewrite ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2 last;
rewrite ^(.*)/forum-(+)-(+)\.html$ $1/forumdisplay.php?fid=$2&page=$3 last;
rewrite ^(.*)/thread-(+)-(+)-(+)\.html$ $1/viewthread.php?
tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3 last;
rewrite ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3 last;
rewrite ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2 last;
}
location ~ \.(png|jpg|gif|bmp|swf)$ {
proxy_store on;
access_log off;
proxy_store_access user:rw group:rw all:rw;
}
location ~ \.php$ {
include /usr/local/nginx/conf/fscgi.conf;
}
}
server {
listen       80;
server_name  sns.linuxsun.cn;
root /www/sns;
location / {
index index.html index.htm index.php;
rewrite ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2 last;
rewrite ^(.*)/forum-(+)-(+)\.html$ $1/forumdisplay.php?fid=$2&page=$3 last;
rewrite ^(.*)/thread-(+)-(+)-(+)\.html$ $1/viewthread.php?
tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3 last;
rewrite ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3 last;
rewrite ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2 last;
}
location ~ \.(png|jpg|gif|bmp|swf)$ {
proxy_store on;
access_log off;
proxy_store_access user:rw group:rw all:rw;
}
location ~ \.php$ {
include /usr/local/nginx/conf/fscgi.conf;
}
}
server {
listen       80;
server_name  ebak.linuxsun.cn;
root /www/ebak;
location / {
index index.html index.htm index.php;
}
location ~ \.(png|jpg|gif|bmp|swf)$ {
access_log off;
proxy_store on;
proxy_store_access user:rw group:rw all:rw;
}
location ~ \.php$ {
include /usr/local/nginx/conf/fscgi.conf;
}
}
server {
listen       80;
server_name  ftp.linuxsun.cn;
root /www/ftp/cnc;
location / {
autoindex on;
index index.html index.htm index.php;
}
location ~ \.(png|jpg|gif|bmp|swf)$ {
proxy_store on;
access_log off;
proxy_store_access user:rw group:rw all:rw;
}
location ~ \.php$ {
include /usr/local/nginx/conf/fscgi.conf;
}
}
=============================================

/usr/local/nginx/conf/fscgi.conf
----------------------------------------
fastcgi_pass  127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
fastcgi_param HTTP_ACCEPT_ENCODING gzip,deflate;
fastcgi_param HTTP_ACCEPT_ENCODING attach;
fastcgi_param HTTP_ACCEPT_ENCODING rar,deflate;
----------------------------------------
vsftpd安裝配置可以看:http://bbs.linuxsun.cn/search.php?
searchid=7&;orderby=lastpost&ascdesc=desc&searchsubmit=yes
/etc/vsftpd.conf
---------------------------------------
# Example config file /etc/vsftpd.conf
anonymous_enable=NO
local_enable=YES
user_config_dir=/etc/vsftpd/user_list
guest_enable=YES
#guest_username=daemon
#pam_service_name=vsftpd
pam_service_name=/etc/pam.d/ftp.vu
connect_from_port_20=YES
write_enable=YES
local_umask=000
dirmessage_enable=YES
xferlog_enable=YES
listen=YES
listen_port=21
------------------------------------
虛擬用戶linuxsun
------------------------------------------
#  cat /etc/vsftpd/user_list/linuxsun
local_umask=077
guest_username=linuxsun
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
local_root=/www/ftp/cnc
-----------------------------------
有一個非常鬱悶的問題。LeapFTP 用linuxsun登錄,上傳一個文件測試下。發現許可權-rw-----
根據網上的資料說,設置成:
local_umask=000
但是我自己測試,就算這樣設置,新上傳的文件許可權還是-rw-----
why????
算了,用crontab 來自動設置許可權吧:
================================
## crontab -l
3 * * * *   /bin/rndc reload 1> /dev/null
10 6 6 * *    /usr/sbin/ntpdate 210.72.145.44
0-1 * * * *  /bin/chmod -R 777 /www/ftp
================================
如果此處許可權不是777的話,Discuz!附件去上傳不了。下載也不行。
php 和mysql的配置文件就不用貼了。。。
基本不做修改。。。
通過以上配置文件,一個高速、穩定的平台出來了。
看下機器的使用情況:
top - 18:20:27 up 1 day,  5:56,  1 user,  load average: 0.00, 0.00, 0.00
Tasks:  74 total,   2 running,  72 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0% us,  0.3% sy,  0.0% ni, 99.7% id,  0.0% wa,  0.0% hi,  0.0% si
Mem:    498900k total,   427408k used,    71492k free,   149696k buffers
Swap:  1052248k total,        0k used,  1052248k free,   109176k cached
一般會出現的問題:
1. No input file specified
2.proxy_pass後圖片不能顯示!
3. discuz!開啟全部偽靜態,首頁能顯示,貼子無法查看。

我完全是從LAMP 移過來的,感覺速度和性能都提高几倍。
在網上翻了不少資料,喜歡的朋友歡迎轉載,在此感謝CU 51cto "NetSeek"
《解決方案》

回復 #1 hjk857 的帖子

nginx 組合fastcgi優勢比較的明顯
《解決方案》

沒測試過.
不過nagios在nginx上有點問題,我一直沒有找到解決辦法
《解決方案》

頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂?????????頂頂  
頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂???????????????頂頂  
頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂??????????????????頂頂  
頂頂頂頂頂頂頂頂頂頂頂????????????????頂頂頂頂頂頂頂頂  
頂頂頂頂頂頂頂頂???????頂???頂頂?????頂頂頂頂頂頂頂頂頂  
頂頂頂????????????頂頂頂頂頂頂????頂頂頂頂頂頂頂頂頂頂  
頂??????????????頂頂頂頂頂頂????頂頂頂頂頂頂頂頂頂頂  
頂????????????頂頂頂頂頂頂頂???????????頂頂頂頂  
頂????????????頂頂頂頂頂頂??????????????頂頂  
頂頂??????????頂頂頂頂頂??????頂頂頂???????頂頂  
頂頂頂頂頂頂頂頂????頂頂頂頂????頂頂頂頂頂頂 ?????頂頂頂  
頂頂頂頂頂頂頂頂????頂頂頂頂????頂頂??頂頂頂?????頂頂頂  
頂頂頂頂頂頂頂頂????頂頂頂頂????頂頂????頂?????頂頂頂  
頂頂頂頂頂頂頂頂????頂頂頂頂????頂頂????頂?????頂頂頂  
頂頂頂頂頂頂頂頂????頂頂頂頂????頂頂???頂頂?????頂頂頂  
頂頂頂頂頂頂頂頂????頂頂頂頂????頂頂???頂頂?????頂頂頂  
頂頂頂頂頂頂頂頂????頂頂頂頂????頂????頂頂?????頂頂頂  
頂頂頂頂頂頂頂頂????頂頂頂頂????頂????頂頂?????頂頂頂  
頂頂頂頂頂頂頂頂????頂頂頂頂????頂????頂頂?????頂頂頂  
頂頂頂頂頂頂頂頂????頂頂頂頂????頂????頂頂?????頂頂頂  
頂頂頂頂頂頂頂頂????頂頂頂頂???頂頂????頂頂?????頂頂頂  
頂頂??頂頂頂?????頂頂頂頂???頂頂???頂頂頂?????頂頂頂  
頂頂??????????頂頂頂頂頂??頂頂??頂頂頂頂?????頂頂頂  
頂頂頂?????????頂頂頂頂頂頂頂頂???頂頂頂頂頂????頂頂頂  
頂頂頂頂頂???????頂頂頂頂頂頂頂頂???頂????頂頂頂頂頂頂頂  
頂頂頂頂頂頂??????頂頂頂頂頂頂頂????頂頂?????頂頂頂頂頂  
頂頂頂頂頂頂頂頂頂???頂頂頂頂頂頂?????頂頂頂???????頂頂  
頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂??????頂頂頂頂頂??????頂頂  
頂頂頂頂頂頂頂頂頂頂頂頂頂頂頂??????頂頂頂頂頂頂???????頂  
頂頂頂頂頂頂頂頂頂頂頂頂頂頂?????頂頂頂頂頂頂頂頂  

個性簽名_______________________________________________________
flashlightbatterylasermountcreechargerpromotional products promotional itemswedding dresses進口密封件人才網投資項目投資項目明星代言明星形象代言形象代言 明星經紀公司演藝經紀公司影視廣告公司廣告公司廣告製作電視廣告投放廣告投放模特公司模特經紀公司模特經紀劇本徵集模特招聘歌手招聘演員招聘演員模特演出公司廣州演出公司北京演出公司上海演出公司深圳演出公司
《解決方案》

原帖由 chenyx 於 2009-3-27 20:27 發表 http://linux.chinaunix.net/bbs/images/common/back.gif
沒測試過.
不過nagios在nginx上有點問題,我一直沒有找到解決辦法

是什麼問題?

我也遇到了一些問題,圖片顯示「X」

net-snmp 啟動不了,161埠沒有開放。

:em14:
《解決方案》

原帖由 hjk857 於 2009-3-28 09:11 發表 http://linux.chinaunix.net/bbs/images/common/back.gif


是什麼問題?

我也遇到了一些問題,圖片顯示「X」

net-snmp 啟動不了,161埠沒有開放。

:em14:
nagios可以用,只不過認證沒有用,nagios的不到認證的用戶名,顯示logined as: ?
《解決方案》

收藏 準備實驗

[火星人 ] Apache 轉移到 Nginx 筆記!已經有644次圍觀

http://coctec.com/docs/service/show-post-23606.html