安装好nginx 后
配置 vim /etc/nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 40000;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
server_tokens off ;#关闭版本显示
client_header_buffer_size 32k;
large_client_header_buffers 4 64k;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
#include /etc/nginx/conf.d/*.conf;
include /data/php/*.conf;
}
/data/php/localnginx.conf
server {
listen 80;
server_name
index index.html index.htm index.php;
root /data/php;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# if (!-e $request_filename) {
# rewrite ^/(.*) /index.php/$1 last;
# }
location ~ \.php
{
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
# fastcgi_pass unix:/dev/shm/php-cgi.sock;
include fastcgi_params;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME /data/myadmin$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
client_max_body_size 1000m;
}
}
绑定本机hosts
192.168.33.10
vagrantfile 配置
# Create a private network, which allows host-only access to the machine
# using a specific IP.
"private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
"public_network"
Linux ip
Paste_Image.png
启动nginx
nginx
ps -ef|grep php
netstat -apn |grep 9000
/etc/init.d/nginx reload
定义Nginx运行的用户和用户组user
nginx进程数,建议设置为等于CPU总核心数。worker_processes 8;
全局错误日志定义类型,[ debug | info | notice | warn | error | crit ]error_log /var/log/nginx/error.log info;
进程文件pid /var/run/nginx.pid;
一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(系统的值ulimit -n)与nginx进程数相除,但是nginx分配请求并不均匀,所以建议与ulimit -n的值保持一致。worker_rlimit_nofile 65535;
FastCGI相关参数是为了改善网站的性能:减少资源占用,提高访问速度。下面参数看字面意思都能理解。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;
nginx跟后端服务器连接超时时间(代理连接超时)proxy_send_timeout 90; #后端服务器数据回传时间(代理发送超时)proxy_read_timeout 90; #连接成功后,后端服务器响应时间(代理接收超时)proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的设置proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)proxy_temp_file_write_size 64k;#设定缓存文件夹大小,大于这个值,将从upstream服务器传}