nginx安装及配置支持php的教程(2)

发布时间:2020-05-15编辑:脚本学堂
nginx安装及配置支持php的教程(2) 紧接上文--- 5、修改Linux Nginx的配置文件,支持PHP

紧接上文(nginx上支持php)---
5、修改linux Nginx的配置文件,支持PHP
 

复制代码 代码如下:

# vi /usr/local/nginx/conf/nginx.conf 
user  nobody; 
worker_processes  8; 
pid  /usr/local/nginx/logs/nginx.pid; 
worker_rlimit_nofile 1024; 
events 
{use epoll; 
worker_connections 1024;} 
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 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; 
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; 
 
server { 
listen   80; 
server_name  www.abcdefg.com; 
root   /var/www/blog; 
index  index.html index.htm index.php; 
location ~ .*.(php|php5)?$ { 
root   html; 
fastcgi_pass   127.0.0.1:9000; 
fastcgi_index  index.php; 
fastcgi_param  SCRIPT_FILENAME  /var/www/blog$fastcgi_script_name; 
includefastcgi_params;} 
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ 
{expires  30d;} 
location ~ .*.(js|css)?$ 
{expires  1h;}
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  /var/logs/access.log  access;}}

注:server部分为PHP虚拟主机127.0.0.1:9000为fastcgi的PC,我这里用的本机/var/www/blog$fastcgi_script_name; 为PHP网页保存的目录测试配置文件:
# /usr/local/nginx/sbin/nginx -t

6、优化Linux内核参数
# vi /etc/sysctl.conf 
在末尾增加以下内容: 
 

复制代码 代码如下:
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 500065000

使配置立即生效:# /sbin/sysctl -p。