nginx常用设置

1. install

install pcre

./configure

make && make install

install nginx

./configure –prefix=/usr/local/nginx –with-zlib=/zlib_soure_dir/

make && make install

2. Install FastCgi init

configure && make Lighttpd

cp /lighttpd_path/src/spawn-fcgi —-> /spawn_fcgi_target_path/

edit fastcgi shell

/spawn_fcgi_target_path/spawn-fcgi -a 127.0.0.1 -p 8002 -C 20 -u nobody -g nobody -f /php_fastcgi_mode_path/bin/php-cgi

3. Control Nginx

Reload new nginx.conf on the running

ps -aux | grep ‘(PID|nginx)’

kill -HUB PID

Upgrading new version server on the running

Kill -HUP old_master_process
kill -QUIT new_master_process
Kill -TERM new_master_process

4. nginx.conf 常用设置说明

#运行用户
user www www;
#工作线程
worker_processes 5;
#错误日志 debug模式
error_log logs/error.log debug;
# 记录Nginx主进程的ID
pid logs/nginx.pid;

events {
#最大连接数
worker_connections 8192;
#运行模式 use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];
# epoll linux only
# 推荐使用epoll
use epoll;
}

http{
#导入配置文件
include conf/mime.types;
#默认类型
default_type application/octet-stream;
#主访问日志
log_format main ‘$remote_addr - $remote_user [$time_local] ‘
‘”$request” $status $bytes_sent ‘
‘”$http_referer” “$http_user_agent” ‘
‘”$gzip_ratio”‘;
#下载日志
log_format download ‘$remote_addr - $remote_user [$time_local] ‘
‘”$request” $status $bytes_sent ‘
‘”$http_referer” “$http_user_agent” ‘
‘”$http_range” “$sent_http_content_range”‘;

#客户端 header 请求超时时间
client_header_timeout 3m;
#客户端 内容 请求超时时间
client_body_timeout 3m;
#客户端发送请求超时时间 established 状态还没有发送回应
send_timeout 3m;

#打开gzip模式
gzip on;
#压缩级别 1-9 1最快 9最慢
gzip_comp_level 5;
#回送给客户端最小的gzip压缩大小
gzip_min_length 1100;
#设置gzip缓存的大小 默认是 4-8k之间
gzip_buffers 4 8k;
#需要使用Gzip压缩的内容Mime集合 每种类型中间用” “空格分割
gzip_types text/plain;

#Linux 2.4+ 可设置 可通过调用内核级 sendfile() 来提高性能
sendfile on;
#freebsd 或 基于TCP_CORK的linux系统可使用
tcp_nopush on;
#只在keep-alive的链接状态中使用
tcp_nodelay on;

#设置保留链接超时时间为75秒 设置header超时时间为20秒
keepalive_timeout 75 20;

#默认虚机配置
server {
#默认虚机端口
listen 80 default;
server_name _ *;
#设置主访问日志,没有独立设置的虚机都将记录与此
access_log logs/default.access.log main;
#设置错误页面路径
error_page 404 http://domain/error_404.html
location / {
index index.html;
root /var/www/default/htdocs;
}
location /i/ {
#设置别名 /i 的访问实际路径是 /spool/w3/images/
alias /spool/w3/images/;
}
}

#设置一个虚拟机
server {
#监听端口
listen 80;
#虚拟机域名
server_name big.server.com;
#访问日志 使用main日志记录格式
access_log logs/big.server.access.log main;
#location 根据不同的URI 提供不同的设置 通过正则匹配
location / {
#设置默认首页
index index.html;
#设置内容根路径
root /var/www/domain1.com/htdocs;
}
#后缀为jpg|jpeg|gif|css|png|js|ico|html的文件作为静态文件,缓存30天,并且不记录访问日志
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires 30d;
}
#设置.ht权限文件禁止访问
location ~ //.ht {
deny all;
}
}

#设置一组名称为big_server_com的服务群
upstream big_server_com {
#可以通过weight来设置权重,如果没有设置,系统将自动为你分配
server 127.0.0.3:8000 weight=5;
#设置该组服务离线
server 127.0.0.3:8001 down;
server 192.168.0.1:8000;
server 192.168.0.1:8001;
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值