linux服务器下LNMP安装与配置方法
发布时间:2023-02-20 09:57:06 所属栏目:LNMP 来源:互联网
导读:注意:关闭rpm默认安装的apache和mysql 1.准备php函数的rpm包 yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2
root html; #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; #连接fastcgi,用来解析php语句 fastcgi_index index.php; #首页为index.php #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #启动fast-cgi,可以在每个服务中启动,也可以放入/usr/local/nginx/conf/fastcgi_params,每个server都可以享用 include fastcgi_params; #包括fastcgi_params中参数 } location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; #图片格式缓存30天 } location ~ .*.(js|css)?$ { expires 1h; #js/css缓存2小时 } 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 /data1/logs/access.log access; } } 15. 在/usr/local/nginx/conf/目录中创建fastcgi_params文件 Vi /usr/local/nginx/conf/fastcgi_params (与配置文件中,只写一个就好) fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #建议把fastcgi_param写到nginx.conf中而不是把它写到fastcgi_params配置文件中,否则配置不够灵活,比如后面默认php设置和alias php设置中,他们的php页面的系统地址是不同的,比如: 默认php文件->/usr/local/nginx/html/index.php Alias php文件->/mnt/bbs/index.php 这个时候你会发现fastcgi_params中的SCRIPT_FILENAME的值是相同的,这样会导致alias php的页面出不来,而配置在nginx.conf中各自配置各自的php系统地址,这样比较灵活. #如果你觉得每个连接php的配置中都要加这一句话有点冗余,那就把它加入到fastcgi_params文件中,这样只需要加一次,其他所有的nginx.conf中的有关连接fastcgi的一块就不用加fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name这一句话了. 16.配置开机启动nginx,php-fpm,ulimit 1)nginx Vi /etc/rc.local /usr/local/nginx/sbin/nginx 2)php-fpm Vi /etc/rc.local /usr/local/php/sbin/php-fpm start 3)ulimit Vi /etc/profile ulimit -SHn 65535 4)mysql Vi /etc/rc.local /usr/local/mysql/bin/mysqld_safe --user=mysql & 17.检查nginx配置文件语句错误 /usr/local/nginx/sbin/nginx -t 18.平滑重启nginx进程 1)Pkill -HUP nginx 2)kill -HUP `pgrep -uroot nginx` Pgrep -uroot nginx 取出nginx主进程PID 3)/usr/local/nginx/sbin/nginx -s reload 19. 编写每天定时切割Nginx日志的脚本 1、创建脚本/usr/local/nginx/sbin/cut_nginx_log.sh vi /usr/local/nginx/sbin/cut_nginx_log.sh #!/bin/bash # This script run at 00:00 # The Nginx logs path logs_path="/usr/local/nginx/logs/" mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/ mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log kill -USR1 `cat /usr/local/nginx/nginx.pid` 2、设置crontab,每天凌晨00:00切割nginx访问日志 crontab -e 00 00 * * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh 20.配置nginx虚拟主机 Sina和sohu域名事先解析 Vi /usr/local/nginx/conf/nginx.conf ==èwww.sina.com公司网站 server { listen 80; server_name www.sina.com; access_log logs/sina.access.log main; location / { root /web/sina; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ .php$ { root /web/sina; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ==èwww.sohu.com公司网站 server { listen 80; server_name www.sohu.com; access_log logs/sohu.access.log main; location / { root /web/sohu; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ .php$ { root /web/sohu; fastcgi_pass 127.0.0.1:9000; (编辑:十堰站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |