这篇文章是参考网上的很多教程通过自我实践解决安装过程中出现的问题总结之后的产物。所有的linux 命令都是在root 账户下执行。所以,如果不是root 权限,需要在语句前加 sudo ,否则肯能会权限不够
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel (-y表示自动选择y)
下载pcre wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz (可以去pcre 官网找到一个最新版的下载链接,确认已经使用yum install
wget)
tar -zxvf pcre-8.35.tar.gz (根据下载的压缩格式不同,解压命令也不同)
cd pcre-8.35 进入解压后的pcre文件目录
./configure
make && make install
查看pcre 版本 pcre-config --version (nginx的安装有可能出现libpcre.so.0共享文件的缺失问题,一般安装pcre 就可以解决)
下载nginx 在官网挑一个stable 的最新版 稳定版
wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar -zxvf nginx-1.10.2.tar.gz
ls -alh | grep nginx 查看nginx size
cd nginx-1.10.2
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
--with-http_ssl_module : 使用https协议模块。默认情况下,该模块没有被构建。前提是openssl与openssl-devel已安装
--with-http_stub_status_module : 用来监控 Nginx 的当前状态
--with-pcre : 设置PCRE库的源码路径,如果已通过yum方式安装,使用--with-pcre自动找到库文件。使用--with-pcre=PATH时,需要从PCRE网站下载pcre库的源码(版
本4.4 – 8.30)并解压,剩下的就交给Nginx的./configure和make来完成。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。
make && make install
安装成功启动nginx
cd /usr/local/nginx/sbin/nginx
cd /usr/local/nginx/sbin/nginx -s reload 重新加载nginx
在 进入 sbin目录之后 可以直接使用 nginx --help 获取更多命令
查看nginx 是否启动 ps -ef|grep nginx
如果通过远程访问失败,则确认nginx 配置文件 /usr/local/nginx/conf/nginx.conf 以及 linux 防火墙
service iptables stop 关闭防火墙, 重启访问出现welcome to nginx 则是防火墙的问题
使用如下命令配置80端口 通过规则
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
service iptables save 保存修改的配置
service iptables restart 重启防火墙
service iptables status 查看防火墙状态