nginx的配置文件
浏览:8833次 出处信息
记录一下,省得每次都到处找。
几个关键地方都有注释,基本看得懂了
nginx.conf
fcgi.conf
nginx启动、停止、重载脚本
/etc/init.d/nginx
安装自启动
用法
几个关键地方都有注释,基本看得懂了
nginx.conf
user nobody nobody;
worker_processes 4; #根据cpu个数来确定
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
access_log off;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
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;
fastcgi_intercept_errors on; #php文件不存在也返回404,无此参数会返回空白页
gzip on;
gzip_static on; #启用此参数nginx编译时需要--with-http_gzip_static_module,用于cdn。否则cdn不能缓存
gzip_disable "MSIE [1-6]\.|Baiduspider"; #IE6不支持压缩,另外百度蜘蛛比较2,不会自解压
gzip_proxied any; #当nginx作为反向代理时,无条件压缩
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_vary on;
server {
listen 80;
server_name xs8.cn www.xs8.cn;
if ($host != 'www.xs8.cn') {
rewrite ^/(.*)$ http://www.xs8.cn/$1 permanent;
}
#以下仅用于CI框架
if (!-f $request_filename) {
rewrite ^/(.*)$ /index.php?$1 last;
}
index index.html index.htm index.php;
root /data/www/xs8.cn;
location ~ .*\.(php|php5)?$ {
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv)$ {
#valid_referers none blocked server_names; #防盗链时打开注释
#if ($invalid_referer) {return 403;} #防盗链时打开注释
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 1h;
}
error_page 404 http://www.xs8.cn/;
access_log off;
}
}
worker_processes 4; #根据cpu个数来确定
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
access_log off;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
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;
fastcgi_intercept_errors on; #php文件不存在也返回404,无此参数会返回空白页
gzip on;
gzip_static on; #启用此参数nginx编译时需要--with-http_gzip_static_module,用于cdn。否则cdn不能缓存
gzip_disable "MSIE [1-6]\.|Baiduspider"; #IE6不支持压缩,另外百度蜘蛛比较2,不会自解压
gzip_proxied any; #当nginx作为反向代理时,无条件压缩
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_vary on;
server {
listen 80;
server_name xs8.cn www.xs8.cn;
if ($host != 'www.xs8.cn') {
rewrite ^/(.*)$ http://www.xs8.cn/$1 permanent;
}
#以下仅用于CI框架
if (!-f $request_filename) {
rewrite ^/(.*)$ /index.php?$1 last;
}
index index.html index.htm index.php;
root /data/www/xs8.cn;
location ~ .*\.(php|php5)?$ {
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv)$ {
#valid_referers none blocked server_names; #防盗链时打开注释
#if ($invalid_referer) {return 403;} #防盗链时打开注释
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 1h;
}
error_page 404 http://www.xs8.cn/;
access_log off;
}
}
fcgi.conf
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
if ($request_filename ~* (.*)\.php) {
set $php_url $1;
}
if (!-e $php_url.php) {
return 403;
}
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
fastcgi_index index.php;
if ($request_filename ~* (.*)\.php) {
set $php_url $1;
}
if (!-e $php_url.php) {
return 403;
}
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
nginx启动、停止、重载脚本
/etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by jackbillow at 2007.10.15.
# it is v.0.0.2 version.
# if you find any errors on this scripts,please contact jackbillow.
# and send mail to jackbillow at gmail dot com.
#
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $nginx_pid
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $nginx_pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
# nginx Startup script for the Nginx HTTP Server
# this script create it by jackbillow at 2007.10.15.
# it is v.0.0.2 version.
# if you find any errors on this scripts,please contact jackbillow.
# and send mail to jackbillow at gmail dot com.
#
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $nginx_pid
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $nginx_pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
安装自启动
chmod +x /etc/init.d/nginx
/sbin/chkconfig nginx on
/sbin/chkconfig -list nginx
/sbin/chkconfig nginx on
/sbin/chkconfig -list nginx
用法
service nginx start
service nginx stop
service nginx restart
service nginx reload
/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
/etc/init.d/nginx reload
service nginx stop
service nginx restart
service nginx reload
/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
/etc/init.d/nginx reload
建议继续学习:
- 配置Nginx+uwsgi更方便地部署python应用 (阅读:105405)
- 搜狐闪电邮箱的 Nginx/Postfix 使用模式 (阅读:32530)
- 解析nginx负载均衡 (阅读:14521)
- Linux 下 PHP 5.2.x 连接 SQL Server 数据库 FreeTDS 配置笔记 (阅读:10104)
- Nginx模块开发入门 (阅读:9882)
- 检查nginx配置,重载配置以及重启的方法 (阅读:9104)
- Cacti 添加 Nginx 监控 (阅读:8923)
- Nginx+FastCgi+Php 的工作机制 (阅读:8859)
- 奇怪的 Nginx 的 upstream timed out 引起响应 502 (阅读:8159)
- Emacs安装配置 (阅读:7310)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
扫一扫订阅我的微信号:IT技术博客大学习
<< 前一篇:Apache用mod_rewrite配置子域名
后一篇:nginx 使用 ssl >>
文章信息
- 作者:废墟 <a@anerg.cn> 来源: 废墟
- 标签: nginx 配置
- 发布时间:2011-10-12 00:14:03
建议继续学习
近3天十大热文
- [46] IOS安全–浅谈关于IOS加固的几种方法
- [45] 图书馆的世界纪录
- [45] 如何拿下简短的域名
- [45] Oracle MTS模式下 进程地址与会话信
- [43] android 开发入门
- [42] 【社会化设计】自我(self)部分――欢迎区
- [41] 界面设计速成
- [41] 读书笔记-壹百度:百度十年千倍的29条法则
- [39] 视觉调整-设计师 vs. 逻辑
- [35] Go Reflect 性能