<--目錄-->
1)生產環境配置文件1
1)生產環境配置文件2
【生產環境配置文件1】
# cat nginx.conf
user www;
worker_processes 4;
worker_cpu_affinity 00000001 00000010 00000100 00001000; #爲每個進程分配cpu,上例中將8個進程分配到8個cpu,當然可以寫多個,或者將一個進程分配到多個cpu。
events {
use epoll; #使用epoll的I/O模型,(linux2.6的高性能方式)
worker_connections 65535; #每個進程允許的最多連接數
}
http
include mime.types;
default_type application/octet-stream;
charset utf-8; #默認編碼GBK
server_names_hash_bucket_size 128;
client_header_buffer_size 128k; #接收header的緩衝區大小
large_client_header_buffers 4 128k; #該指令用於設置客戶端請求的Header頭緩衝區大小,默認值爲4KB。
client_max_body_size 8m; #設置客戶端能夠上傳的文件大小,默認爲1m
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on; #開啓高效文件傳輸模式
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 90; #參數的第一個值指定了客戶端與服務器長連接的超時時間,超過這個時間,服務器將關閉連接。
upstream webgrp{
server 192.168.0.4:8080;
server 192.168.0.6:8080;
}
gzip on; #開啓gzip壓縮輸出
gzip_min_length 1k; #最小壓縮文件大小
gzip_buffers 4 16k; #壓縮緩衝區
gzip_http_version 1.0; #壓縮版本,默認1.1
gzip_comp_level 2; #壓縮等級(1~9)
gzip_types text/plain application/x-javascript text/css application/xml; #壓縮類型,默認就已經包含 test/html
gzip_vary on; #根據HTTP頭來判斷是否需要壓縮
#gzip_disable "MSIE [1-6]\.(?!.*SV1)"; #IE6下對gzip的支持不好,在IE6下禁用gzip
#gzip_disable "MSIE[1-6]."; #IE6下對gzip的支持不好,在IE6下禁用gzip
gzip_disable "MSIE[1-6]."; #IE6下對gzip的支持不好,在IE6下禁用gzip
server {
listen 80;
server_name localhost;
root html;
location ~ .*\.(gif|jpg|jpeg|png|bmp|ioc|swf|raz|zip|txt|flv|mid|doc|ppt|pdf|xls|html|htm|shtml|mp3|wma|js|css)$ {
expires 7d; #7天過期
}
location /api {
rewrite ^/(.*) https://weblbs.chinacloudapp.cn/$1 permanent;
}
location / {
proxy_pass http://webgrp;
proxy_redirect off;
proxy_set_header Host $host; #當後端單臺web服務器上也配置多個虛擬主機時,需要使用Header來區分反向代理哪個主機名
proxy_set_header X-Real-IP $remote_addr; #後端的web服務器可以通過 X-Real-IP/X-Forward-For獲取用戶真實IP
proxy_set_header X-Forward-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90; #後端服務器連接的超時時間
proxy_send_timeout 90; #後端服務器數據回傳時間
proxy_read_timeout 90; #後端服務器處理請求的時間
proxy_buffer_size 4k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k; #在開啓緩衝後服務器響應到臨時文件的功能後,設置nginx每次寫數據到臨時文件的大小限制
proxy_store on; #緩存讀寫規則
proxy_store_access user:rw group:rw all:rw; #緩存讀寫規則
proxy_temp_path /data1/nginx_cache/iis; #存放靜態文件的緩存目錄
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
server_name localhost;#如果這裏做了域名解析,這裏就填域名
listen 443;#監聽端口是443端口
root html;
ssl on;#ssl加密開啓
ssl_certificate /usr/local/nginx/conf/server.crt;#存放的密鑰路徑
ssl_certificate_key /usr/local/nginx/conf/server.key;
location ~ .*\.(gif|jpg|jpeg|png|bmp|ioc|swf|raz|zip|txt|flv|mid|doc|ppt|pdf|xls|html|htm|shtml|mp3|wma|js|css)$ { #列出的靜態文件交給nginx處理
expires 7d; #7天過期
}
location /api {
proxy_pass http://webgrp;
proxy_redirect off;
proxy_set_header Host $host; #當後端單臺web服務器上也配置多個虛擬主機時,需要使用Header來區分反向代理哪個主機名
proxy_set_header X-Real-IP $remote_addr; #後端的web服務器可以通過 X-Real-IP/X-Forward-For獲取用戶真實IP
proxy_set_header X-Forward-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90; #後端服務器連接的超時時間
proxy_send_timeout 90; #後端服務器數據回傳時間
proxy_read_timeout 90; #後端服務器處理請求的時間
proxy_buffer_size 4k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k; #在開啓緩衝後服務器響應到臨時文件的功能後,設置nginx每次寫數據到臨時文件的大小限制
proxy_store on; #緩存讀寫規則
proxy_store_access user:rw group:rw all:rw; #緩存讀寫規則
proxy_temp_path /data1/nginx_cache/iis; #存放靜態文件的緩存目錄
}
}
}
【生產環境配置文件2】
# cat/usr/local/nginx/conf/nginx.conf
user www www;
worker_processes auto;
error_log /home/wwwlogs/nginx_error.log crit;
pid /usr/local/nginx/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;
multi_accept on;
}
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 50m;
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 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
#limit_conn_zone $binary_remote_addr zone=perip:10m;
##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
server_tokens off;
#log format
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
server
{
listen 78 default;
#listen [::]:80 default ipv6only=on;
server_name www.lnmp.org;
index index.html index.htm index.php;
root /home/wwwroot/default;
#error_page 404 /404.html;
location ~ [^/]\.php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
#include pathinfo.conf;
}
location /nginx_status {
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log /home/wwwlogs/access.log access;
}
include web/*.conf;
}
# cat/usr/local/nginx/conf/web/9090.conf
server {
listen 9090;
charset utf-8;
server_name admin234.mini.yaowan.com admin.mini.yaowan.com;
root /ryzc/houtai/;
# autoindex on; #無index時是否顯示文件列表
index index.html index.php;
location / {
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php($|/) {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
}
# cat /usr/local/nginx/conf/web/80.conf
server {
listen 80;
charset utf-8;
server_name _;
root /ryzc/platform/php/auth/htdocs/;
autoindex on; #無index時是否顯示文件列表
index index.html index.php;
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
# cat /usr/local/nginx/conf/web/8080.conf
server {
listen 8080;
autoindex off;
charset utf-8;
server_name sg.wsyht.com;
#Nginx僞靜態規則
location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
root /ryzc/kingdom3/;
index index.html index.php;
location ~ \.php$ {
include fastcgi_params;
}
# access_log /ryzc/wwwlogs/access_80.log access;
}
#緩存網站素材
#location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {
# expires 30d;
#}
#如果使用了僞靜態,則可以保護這些文件的正常訪問
#location ~ /(images|css|js|swf|upload)/.*$ {
#
#}
#禁止某些文件被訪問
#location ~ .*\.(txt|ico)$ {
# break;
#}
#nginx 僞靜態寫法(一定要寫在最後)
#location ~ .*$ {
# rewrite ^/(.*)$ /index.php break; #目錄所有鏈接都指向index.php
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi.conf;
#}
}