安裝CentOS ,配置hosts、靜態IP、設置必要的安全參數等(略)html
[root@vnx ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@vnx ~]# uname -r 2.6.32-696.el6.x86_64 [root@vnx ~]# uname -m x86_64
[root@vnx ~]# rpm -qa gcc gcc-c++ [root@vnx ~]# rpm -qa pcre-devel pcre [root@vnx ~]# rpm -qa zlib zlib-devel [root@vnx ~]# rpm -qa openssl openssl-devel
[root@vnx ~]# yum -y install gcc gcc-c++ [root@vnx ~]# yum -y install pcre-devel pcre [root@vnx ~]# yum -y install zlib zlib-devel [root@vnx ~]# yum -y install openssl openssl-devel
模塊說明:linux
Nginx 是 C語言 開發,安裝 nginx 須要先將官網下載的源碼進行編譯,編譯依賴 gcc 環境,若是沒有 gcc 環境,則須要安裝:nginx
PCRE(Perl Compatible Regular Expressions) 是一個Perl庫,包括 perl 兼容的正則表達式庫。nginx 的 http 模塊使用 pcre 來解析正則表達式,因此須要在 linux 上安裝 pcre 庫,pcre-devel 是使用 pcre 開發的一個二次開發庫。nginx也須要此庫。c++
zlib 庫提供了不少種壓縮和解壓縮的方式, nginx 使用 zlib 對 http 包的內容進行 gzip ,因此須要在 Centos 上安裝 zlib 庫。正則表達式
OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、經常使用的密鑰和證書封裝管理功能及 SSL 協議,並提供豐富的應用程序供測試或其它目的使用。nginx 不只支持 http 協議,還支持 https(即在ssl協議上傳輸http),因此須要在 Centos 安裝 OpenSSL 庫。算法
摘自:centos7安裝Nginx - 極光天際 - 博客園 http://www.javashuo.com/article/p-ufoeyroh-gm.htmlvim
[root@vnx ~]# useradd nginx -s /sbin/nologin -M
[root@vnx ~]# wget --no-check-certificate https://nginx.org/download/nginx-1.14.0.tar.gz [root@vnx ~]# mkdir -p /home/tools [root@vnx ~]# tar -zxf nginx-1.14.0.tar.gz -C /home/tools/ [root@vnx ~]# cd /home/tools/nginx-1.14.0/ [root@vnx nginx-1.14.0]# ./configure --user=nginx --group=nginx --prefix=/app/nginx-1.14.0/ --with-http_stub_status_module --with-http_ssl_module [root@vnx nginx-1.14.0]# make && make install [root@vnx nginx-1.14.0]# ln -s /app/nginx-1.14.0/ /app/nginx
[root@vnx nginx-1.14.0]# tree -d /app/ /app/ ├── nginx -> /app/nginx-1.14.0/ └── nginx-1.14.0 ├── conf ├── html ├── logs └── sbin [root@vnx nginx-1.14.0]# /app/nginx/sbin/nginx -t nginx: the configuration file /app/nginx-1.14.0//conf/nginx.conf syntax is ok nginx: configuration file /app/nginx-1.14.0//conf/nginx.conf test is successful
[root@vnx nginx-1.14.0]# /app/nginx/sbin/nginx [root@vnx nginx-1.14.0]# lsof -i :80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 51611 root 6u IPv4 126537 0t0 TCP *:http (LISTEN) nginx 51612 nginx 6u IPv4 126537 0t0 TCP *:http (LISTEN) [root@vnx nginx-1.14.0]# netstat -lnt | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN [root@vnx nginx-1.14.0]# [root@vnx home]# wget 127.0.0.1 [root@vnx nginx-1.14.0]# curl 127.0.0.1
[root@vnx nginx]# vim /etc/hosts [root@vnx nginx]# tail -1 /etc/hosts 192.168.220.129 vnx www.vnx.com blog.vnx.com bbs.vnx.com
[root@vnx nginx]# diff conf/nginx.conf conf/nginx.conf.default [root@vnx nginx]# egrep -v "#|^$" conf/nginx.conf.default >conf/nginx.conf [root@vnx nginx]# vim conf/nginx.conf [root@vnx nginx]# cat conf/nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.vnx.com; location / { root html/www; index index.html index.htm; } } }
[root@vnx nginx]# mkdir /app/nginx/html/www -p [root@vnx nginx]# echo "http://www.vnx.com" > /app/nginx/html/www/index.html [root@vnx nginx]# cat ../html/www/index.html http://www.vnx.com
[root@vnx nginx]# ./sbin/nginx -t nginx: the configuration file /app/nginx-1.14.0//conf/nginx.conf syntax is ok nginx: configuration file /app/nginx-1.14.0//conf/nginx.conf test is successful [root@vnx nginx]# ./sbin/nginx -s reload
[root@vnx www]# ps -ef | grep nginx root 51797 1 0 04:51 ? 00:00:00 nginx: master process ./sbin/nginx nginx 51877 51797 0 05:01 ? 00:00:00 nginx: worker process root 51912 48379 0 05:11 pts/1 00:00:00 grep nginx [root@vnx www]# [root@vnx www]# curl www.vnx.com http://www.vnx.com