centos7 离线配置安装nginx


下载nginx包

tar -zxvf nginx-1.13.7.tar.gz

cd nginx-1.13.7

安装

./configure

make clean   ####清除./configure时产生的临时文件

可能会报错误 

### the HTTP rewrite module requires the PCRE library.  ###显示需要pcre

rpm -ivh pcre pcre-devle zlib zlib-devle

./configure

执行完成会看到

###

Configuration summary

  + using system PCRE library

  + OpenSSL library is not used

  + using system zlib library

  nginx path prefix: “/usr/local/nginx”

  nginx binary file: “/usr/local/nginx/sbin/nginx”

  nginx modules path: “/usr/local/nginx/modules”

  nginx configuration prefix: “/usr/local/nginx/conf”

  nginx configuration file: “/usr/local/nginx/conf/nginx.conf”

  nginx pid file: “/usr/local/nginx/logs/nginx.pid”

  nginx error log file: “/usr/local/nginx/logs/error.log”

  nginx http access log file: “/usr/local/nginx/logs/access.log”

  nginx http client request body temporary files: “client_body_temp”

  nginx http proxy temporary files: “proxy_temp”

  nginx http fastcgi temporary files: “fastcgi_temp”

  nginx http uwsgi temporary files: “uwsgi_temp”

  nginx http scgi temporary files: “scgi_temp”

####

make

make install

测试是否安装成功

cd /usr/local/nginx

./sbin/nginx -t 

显示结果

[root@192 nginx]# ./sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

cd /usr/local/nginx/sbin

./nginx    ###启动nginx

通过端口查看nginx是否开启

netstat -ntlp | grep 80

###

[root@192 sbin]# netstat -ntlp | grep 80

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7485/nginx: master

###

#重启防火墙

systemctl restart firewalld

firewall-cmd –query-port=80/tcp

firewall-cmd –add-port=80/tcp –permanent

配置nginx开机自启动

vim /etc/rc.d/rc.local

/usr/local/nginx/sbin/nginx

将nginx加入systemctl

vi  /usr/lib/systemd/system/nginx.service

[Unit]

Description=The nginx HTTP and reverse proxy server

After=network.target remote-fs.target nss-lookup.target

[Service]

Type=forking

###通过 find / -name ‘nginx.pid’找到pid的位置

PIDFile=/usr/local/nginx/logs/nginx.pid    

# Nginx will fail to start if /run/nginx.pid already exists but has the wrong

# SELinux context. This might happen when running `nginx -t` from the cmdline.

# https://bugzilla.redhat.com/show_bug.cgi?id=1268621

ExecStartPre=/usr/bin/rm -f /usr/local/nginx/logs/nginx.pid

ExecStartPre=/usr/local/nginx/sbin/nginx -t

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/bin/kill -s HUP $MAINPID

KillSignal=SIGQUIT

TimeoutStopSec=5

KillMode=process

PrivateTmp=true

[Install]

WantedBy=multi-user.target

:wq

保存退出

开启开机启动

systemctl enable nginx.service

systemctl  restart nginx

pkill -9 nginx

systemctl start nginx.service

可以查看相关链接:http://blog.csdn.net/waneto2008/article/details/52729487