nginx配置詳解之main模組
阿新 • • 發佈:2019-02-08
nginx常用全域性配置如下:
user nginx;
worker_processes = 1;
error_log /var/log/nginx/error.log;
worker_rlimit_nofile 20000;
pid /var/run/nginx.pid;
以下為各配置引數的詳細作用:
user nginx;
#指定nginx使用者
worker_processes = 1;
#啟動程序數 通常跟cpu數相等 如不清楚可以設定為auto自動監測 如果想知道自己的系統是幾核的 可以用下列命令
cat /proc/cpuinfo
輸出如下 其中的cpu cores 即為你係統的核數processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 45 model name : Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz stepping : 7 microcode : 1808 cpu MHz : 2300.091 cache size : 15360 KB physical id : 0 siblings : 1 core id : 0 cpu cores : 1 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 13 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc up rep_good unfair_spinlock pni ssse3 cx16 sse4_1 sse4_2 popcnt aes hypervisor lahf_lm bogomips : 4600.18 clflush size : 64 cache_alignment : 64 address sizes : 46 bits physical, 48 bits virtual power management:
error_log /var/log/nginx/error.log;
#錯誤日誌配置 注意路徑許可權
(注:#如果想關閉nginx日誌 error_log off 是不行的 使用error_log /dev/null crit; crit為日誌級別 關於nginx日誌將在在日誌模組詳細介紹)
worker_rlimit_nofile 2000;
#worker程序的最大開啟檔案限制數 如果不設定的話,這個值為作業系統的限制 你可以使用ulimit -a命令來檢視
ulimit -a
輸出如下
其中的open files 即為作業系統的最大限制數 如果nginx出現too many open files 不妨增大這個值core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 7800 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 65535 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 7800 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
pid /var/run/nginx.pid;
#pid 檔案路徑