步骤一:构建Nginx服务器
1)使用源码包安装nginx软件包
[root@proxy ~]# yum -y install gcc pcre-devel openssl-devel //安装依赖包
wget http://nginx.org/download/nginx-1.10.3.tar.gz //下载压缩包
[root@proxy ~]# useradd -s /sbin/nologin nginx //创建执行用户
[root@proxy ~]# tar -xf nginx-1.10.3.tar.gz //解压
[root@proxy ~]# cd nginx-1.10.3
[root@proxy nginx-1.10.3]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-stream
备注:{
--prefix=/usr/local/nginx \ //指定安装路径
--user=nginx \ //指定用户
--group=nginx \ //指定组
--with-http_ssl_module //开启SSL加密功能
--with-stream //开启TCP/UDP代理模块
}
[root@proxy nginx-1.10.3]# make && make install //编译并安装
如果报错:./configure: error: the HTTP rewrite module requires the PCRE library.:
安装pcre-devel解决问题:yum -y install pcre-devel
如果再报错:./configure: error: the HTTP cache module requires md5 functions from OpenSSL library.You can …
- 安装openssl解决问题:yum -y install openssl openssl-devel
- 加参数执行命令:./configure --prefix=/usr/local/nginx
2)nginx命令的用法
1.[root@proxy ~]# /usr/local/nginx/sbin/nginx //启动服务
2.[root@proxy ~]# /usr/local/nginx/sbin/nginx -s stop //关闭服务
3.[root@proxy ~]# /usr/local/nginx/sbin/nginx -s reload //重新加载配置文件
4.[root@proxy ~]# /usr/local/nginx/sbin/nginx -V //查看软件信息
5.[root@proxy ~]# ln -s /usr/local/nginx/sbin/nginx /sbin/ //方便后期使用
步骤二:修改服务器文件配置
修改nginx配置文件 (每次修改后记得使用‘/usr/local/nginx/sbin/nginx -s reload’重新加载nginx)
vim /usr/local/nginx/conf/nginx.conf
1.[root@aaa ~]# vim /usr/local/nginx/conf/nginx.conf
2... ..//html站点
3.server {
4. listen 80;
5. server_name localhost;
6. location / {
7. root html;
8. index index.html index.htm;
9. }
10. }
11. .....//PHP站点
12. server
{
listen 80;
server_name www.aaa.com; ///域名加入hosts文件中
root www/one/public;
location / {
index index.php;
#autoindex on;
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
一个server代表一个站点的配置
修改host文件
vim /etc/hosts
```c
127.0.0.1 www.aaa.com
(如果站点搭建了TP框架,可能会出现runtime文件没有权限问题,使用‘chmod -R 777 runtime’就可以了)
还有PHP系统会自带一个5.4版本,如果要安装其他版本的话感觉很麻烦,但是不安装又不行
PHP安装完之后启动php-fpm然后就行了,只要NGINX环境搭建的没有问题