文章目录
一、安装准备
1.系统版本信息
[root@lnmp ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@lnmp ~]# uname -a
Linux lnmp 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
2.软件包下载
[root@lnmp ~]# ll *.gz
-rw-r–r--. 1 root root 4984397 Aug 4 03:16 libiconv-1.14.tar.gz
-rw-r–r--. 1 root root 186722932 Aug 5 22:10 mysql-5.5.32-linux2.6-x86_64.tar.gz
-rw-r–r--. 1 root root 804164 Aug 5 01:01 nginx-1.6.2.tar.gz
-rw-r–r--. 1 root root 15008639 Aug 4 00:29 php-5.3.27.tar.gz
3.安装nginx所需的依赖于函数库
[root@lnmp ~]# yum install openssl openssl-devel -y
[root@lnmp ~]# yum install pcre pcre-devel -y
[root@lnmp ~]# yum install gcc -y
二、编译安装nginx
1.解压安装包
[root@lnmp ~]# tar xf nginx-1.6.2.tar.gz
[root@lnmp ~]# cd nginx-1.6.2
2.创建nginx用户
[root@lnmp nginx-1.6.2]# useradd nginx -M -s /sbin/nologin
3.编译nginx
[root@lnmp nginx-1.6.2]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.6.2 --with-http_stub_status_module --with-http_ssl_module
[root@lnmp nginx-1.6.2]# make && make install
4.创建目录及软连接管理
[root@lnmp nginx-1.6.2]# mkdir /application
[root@lnmp nginx-1.6.2]# ln -s /usr/local/nginx-1.6.2/ /application/nginx
5.配置环境变量
[root@lnmp nginx-1.6.2]# cp /application/nginx/sbin/* /usr/local/sbin/
三、配置虚拟主机
1.修改配置文件
[root@lnmp nginx-1.6.2]# cd /application/nginx/conf/
[root@lnmp conf]# egrep -v “^$|#” nginx.conf.default > nginx.conf
[root@lnmp conf]# cat -n nginx.conf
1 worker_processes 1;
2 events {
3 worker_connections 1024;
4 }
5 http {
6 include mime.types;
7 default_type application/octet-stream;
8 sendfile on;
9 keepalive_timeout 65;
10 server {
11 listen 80;
12 server_name www.liang.com;
13 location / {
14 root html/www;
15 index index.html index.htm;
16 }
17 }
18 }
[root@lnmp conf]# mkdir …/html/www
[root@lnmp conf]# echo “https://blog.youkuaiyun.com/liang_operations/” > …/html/www/index.html
2.检查语法
[root@lnmp conf]# nginx -t
nginx: the configuration file /usr/local/nginx-1.6.2/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.6.2/conf/nginx.conf test is successful
3.启动nginx
[root@lnmp conf]# nginx
4.关闭防火墙,se
[root@lnmp conf]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@lnmp conf]# setenforce 0