linux高级运维之nginx
安装步骤:按照lnmp这几个字母的顺序进行安装避免出错。 1安装源码包的依赖包yum -y install gcc openssl-devel pcre-devel(地址重写要这个包) zlib-devel
2安装完成nginx并启服务
cd nginx-1.12.2/ 进入解压后的位置
useradd -s /sbin/nolgin/ nginx 创建一个不能登录端用户
./configure --help模块不记得了就help
./configure --prefix=/usr/local/nginx/ --user=nginx --group=nginx
--with-http_ssl_module --with-stream --with-http_stub_status_module
--without-http_autoindex_module --without-http_ssi_module
--with-http_ssl_module 加密模块
--with-stream 代理模块
--with-http_stub_status_module 查看nginx状态模块
--without-http_autoindex_module 禁用文件索引模块
--without-http_ssi_module
以上是常用模块可以根据需要自行选择
make && make install
ln -s /usr/local/nginx/sbin/nginx /sbin/
nginx
ss -natulp |grep 80
3安装mariadb(客户端 启动服务) mariadb-server(服务端 提供mysql命名) mariadb-devel(依赖包)
如果是mysql就安装mysql
yum -y installmariadbmariadb-servermariadb-devel
安装nosql数据库
yum -y install memcached
4安装php(解释器) php-mysql(调用mariadb数据库的模块)
php-fpmphp-pecl-memcache(调用memcache数据库的模块)
cd php_scripts/
yum -y installphpphp-mysql
yum -y install php-pecl-memcache
yum -y install php-fpm-5.4.16-42.el7.x86_64.rpm
5启服务和关防火墙
服务:nginx mariadb php-fpm memcached
nginx
systemctl restart mariadb
systemctl enable mariadb
systemctl restart php-fpm
systemctl enable php-fpm
systemctl restart memcached.service
systemctl enable memcached
setenforce 0
firewall-cmd --set-default-zone=trusted
6修改配置文件使能够访问php动态网站(动静分离)
vim /usr/local/nginx/conf/nginx.conf //nginx配置文件
#location 位置nginx 让用户进入
#nginx 做判断静态或动态静态直接给动态要交给php解释器
#location匹配用户地址栏
#同个server下可以多个location
#匹配及停止,类似if elif else的判断
location / { #/的优先级最低什么都找不着就匹配根
root html;
indexindex.phpindex.html index.htm;
#设置默认首页为index.php(只写域名或IP时)
}
location~\.php${ #nginx支持正则 ~匹配。类似awk的~号匹配(帮用户找php)
root html;
fastcgi_pass 127.0.0.1:9000; //找到php交给9000端口解释
fastcgi_indexindex.php;
#fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name;
include fastcgi.conf; //fastcgi.conf 一堆环境变量
}
#改错了可以cp nginx.conf.default nginx.conf还原配置文件
vim /etc/php-fpm.d/www.conf //php配置文件默认不用修改
listen = 127.0.0.1:9000 //PHP端口号
pm.max_children = 32 //php是多进程的;最大进程数量
pm.start_servers = 15 //最小进程数量
pm.min_spare_servers = 5 //最少需要几个空闲着的进程
随时待命一旦小于5个就自动再开启了
pm.max_spare_servers = 32 //最多允许几个进程处于空闲状态
7验证结果:
cp mem.php/usr/local/nginx/html
curl 192.168.2.111/mem.php (结果为test)
页:
[1]