nginx相关

安装

1、关闭防火墙

在Linux系统中默认有防火墙Iptables管理者所有的端口,只启用默认远程连接22端口其他都关闭,咱们上面设置的80等等也是关闭的,所以我们需要先把应用的端口开启。
方法一:直接关闭防火墙,这样性能较好,但安全性较差,如果有前置防火墙可以采取这种方式:

# 关闭防火墙
[[email protected] ~]# service iptables stop
# 关闭开机自启动防火墙
[[email protected] ~]# chkconfig iptables off
[[email protected] ~]# chkconfig --list|grep ipt

下面是防火墙的其他操作命令:
nginx相关

方法二:将开启的端口加入防火墙白名单中,这种方式较安全但性能也相对较差:

#编辑防火墙白名单
[[email protected] ~]# vim /etc/sysconfig/iptables
#增加下面一行代码
-A INPUT -p tcp -m state -- state NEW -m tcp --dport 80 -j ACCEPT
#保存退出,重启防火墙
[[email protected] ~]# service iptables restart

nginx相关

2、关闭selinux

Linux安装好之后,通常SELinux都是处于默认的开启状态,开启的情况下可能会导致一些服务安装失败。所以,在不需要的情况下完全可以关闭掉。
1.查看SELinux的状态:

[[email protected] ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28

2.永久关闭SELinux
修改配置文件/etc/selinux/config,将其中的SELINUX=enforcing改为SELINUX=disabled:

[[email protected] ~]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

3.重启系统,再执行sestatus查看状态:

reboot
[[email protected] ~]# sestatus
SELinux status:                 disabled

3、下载Nginx及相关组件

Linux系统是Centos 6.5 64位,我直接切换到root用户下安装。
nginx相关
进入用户目录下载程序:
nginx相关

下载相关组件:

[[email protected] src]# wget http://nginx.org/download/nginx-1.10.2.tar.gz
省略安装内容...
[[email protected] src]# wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
省略安装内容...
[[email protected] src]# wget http://zlib.net/zlib-1.2.11.tar.gz
省略安装内容...
[[email protected] src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
省略安装内容...

安装c++编译环境,如已安装可略过。

4、安装Nginx及相关组件

都是先解压,随后 配置、make和安装三合一。

openssl安装:

[[email protected] src]# tar zxvf openssl-fips-2.0.10.tar.gz
省略安装内容...
[[email protected] src]# cd openssl-fips-2.0.10
[[email protected] openssl-fips-2.0.10]# ./config && make && make install
省略安装内容...

pcre安装

[[email protected] src]# tar zxvf pcre-8.40.tar.gz
省略安装内容...
[[email protected] src]# cd pcre-8.40
[[email protected] pcre-8.40]# ./configure && make && make install
省略安装内容...

zlib安装

[[email protected] src]# tar zxvf zlib-1.2.11.tar.gz
省略安装内容...
[[email protected] src]# cd zlib-1.2.11
[[email protected] zlib-1.2.11]# ./configure && make && make install
省略安装内容...

nginx安装

[[email protected] src]# tar zxvf nginx-1.10.2.tar.gz
省略安装内容...
[[email protected] src]# cd nginx-1.10.2
[[email protected] nginx-1.10.2]# ./configure && make && make install
省略安装内容...

5、启动Nginx

先找一下nginx安装到什么位置上了。
nginx相关
进入nginx目录并启动:
1、用whereis libpcre.so.1命令找到libpcre.so.1在哪里
2、用ln -s /usr/local/lib/libpcre.so.1 /lib64命令做个软连接就可以了
3、用sbin/nginx启动Nginx
4、用ps -aux | grep nginx查看状态

[[email protected] nginx]# whereis libpcre.so.1
[[email protected] nginx]# ln -s /usr/local/lib/libpcre.so.1 /lib64
[[email protected] nginx]# sbin/nginx
[[email protected] nginx]# ps -aux | grep nginx 

nginx相关

查看nginx是否启动的方法:

[[email protected] nginx]# lsof -i:80

nginx相关

[[email protected] nginx]# netstat -ntpl

nginx相关

进入Linux系统的图形界面,打开浏览器输入localhost会看到下图,说明nginx启动成功。
nginx相关
在浏览器界面*问:
nginx相关

利用elinks文本浏览器访问,没有缓存!

[[email protected] nginx]# yum install elinks

nginx相关

用的windows系统,配置一下host在“C:\Windows\System32\drivers\etc”下的hosts中配置一下域名重定向
10.11.13.22 nginx.test.com nginx.test1.com nginx.test2.com
然后cmd再ping一下这个域名是否正确指向了这个IP上。