天天看點

nginx啟動腳本和配置檔案

一. nginx.conf 

①vim /usr/local/nginx/conf/nginx.conf //清空原來的配置,加入如下内容:

user nobody nobody;

worker_processes 2;

error_log /usr/local/nginx/logs/nginx_error.log crit;

pid /usr/local/nginx/logs/nginx.pid;

worker_rlimit_nofile 51200;

events

{

    use epoll;

    worker_connections 6000;

}

http

    include mime.types;

    default_type application/octet-stream;

    server_names_hash_bucket_size 3526;

    server_names_hash_max_size 4096;

    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'

    '$host "$request_uri" $status'

    '"$http_referer" "$http_user_agent"';

    sendfile on;

    tcp_nopush on;

    keepalive_timeout 30;

    client_header_timeout 3m;

    client_body_timeout 3m;

    send_timeout 3m;

    connection_pool_size 256;

    client_header_buffer_size 1k;

    large_client_header_buffers 8 4k;

    request_pool_size 4k;

    output_buffers 4 32k;

    postpone_output 1460;

    client_max_body_size 10m;

    client_body_buffer_size 256k;

    client_body_temp_path /usr/local/nginx/client_body_temp;

    proxy_temp_path /usr/local/nginx/proxy_temp;

    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;

    fastcgi_intercept_errors on;

    tcp_nodelay on;

    gzip on;

    gzip_min_length 1k;

    gzip_buffers 4 8k;

    gzip_comp_level 5;

    gzip_http_version 1.1;

    gzip_types text/plain application/x-javascript text/css text/htm application/xml;

     include vhosts/*.conf;

②預設的虛拟主機檔案:

cd /usr/local/nginx/conf

    mkdir vhosts

    cd vhosts

    vim default.conf ,加入下面的内容:

server

    listen 80 default_server;

    server_name localhost;

    index index.html index.htm index.php;

    root /usr/local/nginx/html;-----------------------網站的目錄

    location ~ \.php$ {

        include fastcgi_params;

        fastcgi_pass unix:/tmp/php-fcgi.sock;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME   /usr/local/nginx/html$fastcgi_script_name;-------網站的目錄

    }

二. php-fpm.conf

vim   /usr/local/php/etc/php-fpm.conf     //把之前的内容清空,然後寫入如下配置:

[global] 

pid = /usr/local/php/var/run/php-fpm.pid

error_log = /usr/local/php/var/log/php-fpm.log 

[www] 

listen = /tmp/php-fcgi.sock 

user = php-fpm 

group = php-fpm

listen.owner = nobody  //和後面的nginx的一緻

listen.group = nobody // 同上

pm = dynamic 

pm.max_children = 50 

pm.start_servers = 20 

pm.min_spare_servers = 5 

pm.max_spare_servers = 35 

pm.max_requests = 500 

rlimit_files = 1024 

配置多個pool

[global]

...

[domain1.com]

[domain2.com]

慢執行日志

slowlog = /path/to/slow.log-----監控腳本執行慢

request_slowlog_timeout = 1

open_basedir

php_admin_value[open_basedir]=/data/www/:/tmp/

動态、靜态子程序pm = static/dynamic

如果選擇static,則由pm.max_children指定固定的子程序數。

如果選擇dynamic,則由以下參數決定:

pm.max_children ,子程序最大數

pm.start_servers ,啟動時的程序數

pm.min_spare_servers ,保證空閑程序數最小值,如果空閑程序小于此值,則建立新的子程序

pm.max_spare_servers ,保證空閑程序數最大值,如果空閑程序大于此值,此進行清理

對于專用伺服器,pm可以設定為static。

下一篇: shell變量

繼續閱讀