十、nginx配置
1.在/usr/local/nginx/conf/目录中创建nginx.conf文件:
rm -f /usr/local/nginx/conf/nginx.conf
vi /usr/local/nginx/conf/nginx.conf
=======================================
nginx.conf才是nginx web服务器的配置文件
=======================================
user www www; /*启动nginx服务的用户与组*/
worker_processes 1; /*启动nginx服务的工作进程*/
error_log logs/nginx_error.log crit; /*错误日志,以及等级*/
pid /usr/local/nginx/nginx.pid; /*nginx服务进程PID*/
worker_rlimit_nofile 51200;
events
{
use epoll; /*工作模式*/
worker_connections 51200; /*每进程允许最大的同时连接数*/
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
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;
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;
#limit_zone crawler $binary_remote_addr 10m;
server
{
listen 80; /*监听端口*/
server_name localhost; /*服务器名称*/
index index.html index.htm index.php; /*缺省主页名称*/
root /usr/local/nginx/html; /*网站根目录,也可以采用下面内容*/
#也可以采用相对路径,下面注释部分*/
#location / {
# root html;
# index index.html index.htm;
# }
#limit_conn crawler 20;
#通过FastCGI方式支持PHP,php页面由fastcgi代理处理,这也是反向代理的一个应用,这里可以是jsp/asp等脚本。
#Nginx是通过本机的9000端口将PHP请求转发给PHP的,PHP自己是从本机的9000端口侦听数据,Nginx与PHP通过本机的9000端口完成了数据请求。
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000; /*fastcgi监听端口*/
fastcgi_index index.php;
include fcgi.conf; /*fastcgi配置文件,修改为以下内容*/
}
#对于某一类型的文件,设置过期时间,静态的页面通常设置长一点。
#静态文件,nginx自己处理
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
expires 30d;
}
#日志的格式
log_format access '$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 access;
}
}
说明:以上配置文件只是基本配置文件,要实现其它功能的话,需要在此基础上进行修改。
2.在/usr/local/nginx/conf/目录中创建fcgi.conf文件:
说明:可以直接粘贴以下内容。
vi /usr/local/nginx/conf/fcgi.conf
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;