51学通信论坛2017新版
标题:
Nginx安装-Centos7
[打印本页]
作者:
admin
时间:
2017-11-15 21:04
标题:
Nginx安装-Centos7
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
yum install iptables-services #安装
vi /etc/sysconfig/iptables #编辑防火墙配置文件
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
:wq! #保存退出
systemctl restart iptables.service #最后重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动
关闭SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效
1、进入nginx目录
[root@localhost nginx-1.11.2]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
然后执行 ./configure #主要的作用是对即将安装的软件进行配置,检查当前的环境是否满足要安装软件的依赖关系
[root@localhost nginx-1.11.2]# ./configure
checking for OS
+ Linux 3.10.0-327.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
简单解释:Gcc编译器能将C、C++语言源程序、汇程式化序和目标程序编译、连接成可执行文件。
2、yum解决 yum install gcc
1)然后再次执行 ./configure
报错:./configure: error: the HTTP rewrite module requires the PCRE library.
PCRE是一个NFA正则引擎,不然不能提供完全与Perl一致的正则语法功能。但它同时也实现了DFA,只是满足数学意义上的正则。
yum install -y pcre pcre-devel
2)然后再次执行 ./configure
报错:./configure: error: the HTTP gzip module requires the zlib library.
libpng 是一套免费的、公开源代码的程序库,支持对 PNG 图形文件的创建、读写等操作。libpng 使用 zlib 程序库作为压缩引擎,zlib 也是著名的 gzip (GNU zip) 所采用的压缩引擎。
yum install -y zlib-devel
3)继续往下做缺少什么依赖就装即可 这里解决依赖 yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel ncurses ncurses-devel
gcc、gc++、make先下载到本地
3、安装
./configure \
–prefix=/usr/local/nginx \
–sbin-path=/usr/local/nginx/sbin/nginx \
–conf-path=/usr/local/nginx/conf/nginx.conf \
–error-log-path=/usr/local/nginx/logs/error.log \
–http-log-path=/usr/local/nginx/logs/access.log \
–pid-path=/usr/local/nginx/run/nginx.pid \
–lock-path=/usr/local/nginx/lock/nginx.lock \
–user=nginx \
–group=nginx \
–with-http_ssl_module \
–with-http_realip_module \
–with-http_stub_status_module \
–with-http_gzip_static_module \
–http-proxy-temp-path=/usr/local/nginx/tmp/nginx/proxy/ \
–http-fastcgi-temp-path=/usr/local/nginx/tmp/nginx/fcgi/ \
–http-uwsgi-temp-path=/usr/local/nginx/tmp/nginx/uwsgi
最后给出安装位置信息
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: “/usr/local/nginx”
nginx binary file: “/usr/local/nginx/sbin”
nginx modules path: “/usr/local/nginx/modules”
nginx configuration prefix: “/usr/local/nginx”
nginx configuration file: “/usr/local/nginx/nginx.conf”
nginx pid file: “/usr/local/nginx/run/nginx.pid”
nginx error log file: “/usr/local/nginx/log/error.log”
nginx http access log file: “/usr/local/nginx/log/access.log”
nginx http client request body temporary files: “/usr/local/nginx/tmp/nginx/client/”
nginx http proxy temporary files: “/usr/local/nginx/tmp/nginx/proxy/”
nginx http fastcgi temporary files: “/usr/local/nginx/tmp/nginx/fcgi/”
nginx http uwsgi temporary files: “/usr/local/nginx/tmp/nginx/uwsgi”
nginx http scgi temporary files: “scgi_temp”
make && make install
/usr/local/nginx/sbin/nginx -t #查看配置是否正确
useradd -M -s /sbin/nologin nginx
groupadd -f nginx
/usr/local/nginx/sbin/nginx -V #查看可编译选项,能找到安装路径信息
启动时一些命令:
nginx -t
#启动nginx
nginx
#说一下nginx启动的一些事情
#一般来说在nginx的配置文件修改后进行如下操作,nginx -t检测一下配置文件是否正确,如果正确的话
#再使用nginx -s reload 使nginx平滑启动
#把nginx添加到开机启动
vim /etc/rc.local
#在最后新加一行
/usr/local/nginx/sbin/nginx
#查看nginx是否启动
netstat -tunpl | grep 80
pstree 看下有没有nginx就行了
声明:本文转载自网络。版权归原作者所有,如有侵权请联系删除。
欢迎光临 51学通信论坛2017新版 (http://bbs.51xuetongxin.com/)
Powered by Discuz! X3