LNMP是Linux+Nginx+MySQL+PHP的简称,是一套完整的PHP网站服务器架构环境。所用Linux发行版为Ubuntu14. 04,所有需要的软件均使用Ubuntu自带apt源下载安装。Ubuntu默认登录不是root用户;所以要加sudo命令才能执行某些 命令;root用户不用加sudo就可以执行命令;如:普通用户:sudo?apt-getupdateroot用户:apt-get update安装Nginx1】添加nginxUbuntuapt-get源#备份原有配置文件root@zhangyu1:~#?c p?/etc/apt/sources.list?/etc/apt/sources.listbak#编辑,在sources.list 文件下面添加以下代码:root@zhangyu1:~#?vim?/etc/apt/sources.listdeb?http://n ginx.org/packages/ubuntu/http://nginx.org/packages/ubuntu/?lucid? nginxdeb-src?http://nginx.org/packages/ubuntu/http://nginx.org/pa ckages/ubuntu/?lucid?nginx2】#下载签名证书root@zhangyu1:~#?wget?http://n ginx.org/packages/keys/nginx_signing.keyhttp://nginx.org/packages /keys/nginx_signing.key#添加证书root@zhangyu1:~#?apt-keyaddnginx_si gning.key3】更新Ubuntu源:root@zhangyu1:~#?apt-getupdate4】安装nginxroot @zhangyu1:~#?apt-getinstall-ynginx5】查看nginx版本号mailto:zhangyu-1 @zhangyu1zhangyu-1@zhangyu1:$?nginx?-vnginx?version:?nginx/1.8.0等 待nginx安装完成后,打开浏览器,在地址栏输入localhost,检测nginx是否开启;若开启成功,则会显示欢迎使用Nginx 的界面;若没有,则在终端下输入以下命令即可打开nginx:sudo/etc/init.d/nginxstart6】nginx相 关文件和目录mailto:zhangyu-1@zhangyu1zhangyu-1@zhangyu1:~$?find?/?-name ?"nginx"/usr/sbin/nginx?????????????????nginx启动文 件/usr/share/nginx/html????????????WEB目录/etc/nginx配置文件目 录/etc/init.d/nginx启动文件/var/log/nginx?日志目录7】nginx命令记录重启nginxmailto :root@zhangyu1root@zhangyu1:~#?service?nginx?restart??Restarting ?nginx?nginx????????????????????????????????????????????????[?OK? ]停止nginxmailto:root@zhangyu1root@zhangyu1:~#?service?nginx?stop启动 nginxmailto:root@zhangyu1root@zhangyu1:~#?service?nginx?start平滑重启 (可以在不关闭nginx的情况下;重新加载配置文件)mailto:root@zhangyu1root@zhangyu1:~#?se rvice?nginx?reload??Reloading?nginx?nginx??????????????????????? ??????????????????????????[?OK?]?#检查配置文件(每次修改完nginx配置文件都要用这条命令检查; 如果有错会报出来)mailto:root@zhangyu1root@zhangyu1:~#?/usr/sbin/nginx?-t? nginx:?the?configuration?file?/etc/nginx/nginx.conf?syntax?is?okn ginx:?configuration?file?/etc/nginx/nginx.conf?test?is?successful #查看nginx启动状况mailto:root@zhangyu1root@zhangyu1:/etc/nginx/conf.d#? ps?-ef?|grep?nginxroot?????21848??8860??0?17:10?pts/9????00:00:00 ?tail?-f?/var/log/nginx/error.logroot?????22457?????1??0?18:04??? ???????00:00:00?nginx:?master?process?/usr/sbin/nginx?-c?/etc/ngi nx/nginx.confwww-data?22460?22457??0?18:04??????????00:00:00?ngin x:?worker?processroot?????22626?22580??0?19:09?pts/1????00:00:00? grep?--color=auto?nginx########################################## ##############配置nginx1】配置/etc/nginx/nginx.conf文件#备份原有配置文件root@zha ngyu1:~#?cp/etc/nginx/nginx.conf/etc/nginx/nginx.confbak?#编译ngi nx.conf文件root@zhangyu1:~#?vim/etc/nginx/nginx.conf#修改nginx运行账号为: www-data组的www-data用户userwww-data;?http?{?include???????/etc/ngin x/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"?"$h ttp_x_forwarded_for"'';?access_log??/var/log/nginx/access.log??mai n;?sendfile????????on;#keepalive_timeout??65;#在配置文件里加入下面的话;?tc p_nopush?????on;?tcp_nodelay????on;?keepalive_timeout??120;?gzip? on;?gzip_min_length??1k;?gzip_buffers?????4?16k;?gzip_types?????? ?text/plain?application/x-javascript?text/css?application/xml;?gz ip_vary?on;#客户端请求头部的缓冲区大小,这个可以根据你的系统分页大小来设置client_header_buffer _size?256k;#客户请求头缓冲大小large_client_header_buffers?4?256k;#连接到后端 fastcgi超时时间?fastcgi_connect_timeout?300;#向fastcgi请求超时时间(这个指定值已经完 成两次握手后向fastcgi传送请求的超时时间)?fastcgi_send_timeout?300;#接收fastcgi应答超时 时间,同理也是2次握手后?fastcgi_read_timeout?300;#读取fastcgi应答第一部分需要多大缓冲区,该值 表示使用1个64kb的缓冲区读取应答第一部分(应答头),可以设置为fastcgi_buffers选项缓冲区大小?fastcgi_b uffer_size?64k;#指定本地需要多少和多大的缓冲区来缓冲fastcgi应答请求,假设一个php或java脚本所产生页 面大小为256kb,那么会为其分配4个64kb的缓冲来缓存;若页面大于256kb,那么大于的256kb的部分会缓存到fastcg i_temp指定路径中,这并非是个好办法,内存数据处理快于硬盘,一般该值应该为站点中php/java脚本所产生页面大小中间值,如 果站点大部分脚本所产生的页面大小为256kb,那么可把值设置为1616k,464k等?fastcgi_buffers?4?12 8k;#默认值是fastcgi_buffer的2倍?fastcgi_busy_buffers_size?128k;#写入缓存文 件使用多大的数据块,默认值是fastcgi_buffer的2倍?fastcgi_temp_file_write_size?256k ;#后端服务器连接的超时时间_发起握手等候响应超时时间proxy_connect_timeout????5;#连接成功后_等 候后端服务器响应时间_其实已经进入后端的排队之中等候处理(也可以>说是后端服务器处理请求的时间)proxy_read_timeo ut???????60;#后端服务器数据回传时间_就是在规定时间之内后端服务器必须传完所有的数据proxy_send_time out???????5;#设置从被代理服务器读取的第一部分应答的缓冲区大小,通常情况下这部分应答中包含>一个小的应答头,默认情况 下这个值的大小为指令proxy_buffers中指定的一个缓冲区的大>小,不过可以将其设置为更小proxy_buffer_siz e????????16k;#设置用于读取应答(来自被代理服务器)的缓冲区数目和大小,默认情况也为分页大小>,根据操作系统的不同可 能是4k或者8kproxy_buffers????????????4?64k;?include?/etc/nginx/conf. d/.conf;}2】配置虚拟主机文件/etc/nginx/conf.d/default.conf#备份原有配置文件root@z hangyu1:~#?cp/etc/nginx/conf.d/default.conf/etc/nginx/conf.d/de fault.confbak#编辑default.conf文件root@zhangyu1:~#?vim/etc/nginx/con f.d/default.conf?#编辑#增加index.phplocation?/?{?root???/usr/share/ nginx/html;?index??index.html?index.htm?index.php;}#取消下面七行的注释l ocation?~?\.php$?{#把html修改为/usr/share/nginx/html?root/usr/share/ nginx/html;?#下面对应的是/etc/php5/fpm/pool.d/http://www.conf/www.conf文 件里的listen语句??fastcgi_pass???127.0.0.1:9000;?fastcgi_index??index. php;?#注释下面这句话?#fastcgi_param??SCRIPT_FILENAME??/scripts$fastcgi_s cript_name;?#添加下面的语句;也写在/etc/nginx/fastcgi_params文件;必写??fastcgi_p aram??SCRIPT_FILENAME??$document_root$fastcgi_script_name;?includ e????????fastcgi_params;?}####################################### #################接下来修改?fastcgi_params文件:root@zhangyu1:~#?vim/etc /nginx/fastcgi_params在该文件的末尾添加如下行:fastcgi_paramSCRIPT_FILENAME$ document_root$fastcgi_script_name;保存退出。########################## ###############################检查配置文件(每次修改完nginx配置文件都要用这条命令检查;如果有 错会报出来)mailto:root@zhangyu1root@zhangyu1:~#?/usr/sbin/nginx?-t?ngi nx:?the?configuration?file?/etc/nginx/nginx.conf?syntax?is?okngin x:?configuration?file?/etc/nginx/nginx.conf?test?is?successful重启n ginxmailto:root@zhangyu1root@zhangyu1:~#?service?nginx?restart?? Restarting?nginx?nginx??????????????????????????????????????????? ?????[?OK?]#查看nginx启动状况mailto:root@zhangyu1root@zhangyu1:/etc/nginx/conf.d#?ps?-ef?|grep?nginxroot?????21848??8860??0?17:10?pts/9????00:00:00?tail?-f?/var/log/nginx/error.logroot?????22457?????1??0?18:04??????????00:00:00?nginx:?master?process?/usr/sbin/nginx?-c?/etc/nginx/nginx.confwww-data?22460?22457??0?18:04??????????00:00:00?nginx:?worker?processroot?????22626?22580??0?19:09?pts/1????00:00:00?grep?--color=auto?nginx |
|