CentOS-5.1 yum安裝Nginx + PHP-FPM + MySQL筆記

昨天完成安裝,筆記如下

先新建一個 repo

# vi /etc/yum.repos.d/centos.21andy.com.repo
[21Andy.com]
name=21Andy.com Packages for Enterprise Linux 5 - $basearch
baseurl=http://www.21andy.com/centos/5/$basearch/
enabled=1
gpgcheck=0
protect=1


啓用 EPEL repo
i386
rpm -ihv http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

接着導入key
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL

yum install nginx php-fpm mysql-server

yum -y mysql-server
service mysqld start
mysqladmin -u root password root
service mysqld stop

看下我的完整安裝,只要一句
yum -y install nginx mysql-server php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator
yum -y update
chkconfig --level 345 mysqld on
chkconfig --level 345 php-fpm on
chkconfig --level 345 nginx on

groupadd www
useradd -g www www

mkdir -p /www/logs/
chown -Rvf www:www /www/
vi /etc/nginx/fastcgi_params

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;   # zhangtuo edit


mv  /etc/nginx/nginx.conf /etc/nginx/nginx.conf_bak_zhangtuo


vi /etc/nginx/nginx.conf
user www www;
worker_processes 8;
error_log  /www/logs/nginx_error.log  crit;

pid /www/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events {
    use epoll;
    worker_connections 51200;
}

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

    #charse  gb2312; # Ĭȱ࣬¿ÉԲ»ÉÖ

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

    sendfile on;
    tcp_nopush     on;

    keepalive_timeout 60;

    tcp_nodelay on;

    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.0;
    gzip_comp_level 5;
    gzip_types       text/plain text/javascript application/x-javascript text/css application/xml;
    gzip_vary on;

    #limit_zone  crawler  $binary_remote_addr  10m;
    server {
        listen 80;
        server_name localhost;
        root  /www/wwwroot/;
        location /status {
            stub_status on;
            access_log  off;
        }
        location / {
            try_files $uri $uri/ /error.php?q=$uri&$args;
        }
        
        include server.conf;

        log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
        access_log  /www/logs/access.log  access;
    }
}




vi /etc/nginx/server.conf
index index.html index.htm index.php;

#limit_conn   crawler  20;

location ~ /\.ht {
    deny all;
}

location ~ .*\.(sqlite|sq3)$ {
    deny all;
}

location ~ \.php$ {
    root           /www/wwwroot;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ {
    expires      30d;
    access_log   off;
}

location ~ .*\.(js|css)?$ {
    expires      30d;
    access_log   off;
}


service mysqld stop
mysqld_safe --skip-grant-tables &
mysql
use mysql
update user set password=PASSWORD("banGIAN2008")  where user='root'; 
service mysqld start

完整的nginx.conf 文件如下

user www www;
worker_processes 8;
error_log  /www/logs/nginx_error.log  crit;

pid /www/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events {
    use epoll;
    worker_connections 51200;
}

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

    #charse  gb2312; # Ĭȱ࣬¿ÉԲ»ÉÖ

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

    sendfile on;
    tcp_nopush     on;

    keepalive_timeout 60;

    tcp_nodelay on;

    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.0;
    gzip_comp_level 5;
    gzip_types       text/plain text/javascript application/x-javascript text/css application/xml;
    gzip_vary on;

    #limit_zone  crawler  $binary_remote_addr  10m;
    server {
        listen 80;
        server_name localhost;
        root  /www/wwwroot/;
        location /status {
            stub_status on;
            access_log  off;
        }
        location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;
        }
        
        include server.conf;

        log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
        access_log  /www/logs/access.log  access;
    }
}

完整的server.conf文件內容如下

index index.html index.htm index.php;

#limit_conn   crawler  20;

location ~ /\.ht {
    deny all;
}

location ~ .*\.(sqlite|sq3)$ {
    deny all;
}

location ~ \.php$ {
    root           /www/wwwroot;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ {
    expires      30d;
    access_log   off;
}

location ~ .*\.(js|css)?$ {
    expires      30d;
    access_log   off;
}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章