Nginx安裝

Nginx安裝:
方式1. yum安裝
配置nginx的yum源,而後用yum install -y nginx來安裝html

方式2. 源碼安裝
#1. 中止原有web服務器nginx

#2. 添加普通用戶帳號來運行nginx:
useradd nginx -M -r -s /sbin/nologinweb

#2.1 安裝依賴包
yum install -y gcc pcre-devel openssl-devel服務器

#3. 解壓並安裝Nginx:
wget + nginx官網本身想要的nginx版本連接(我選的的是nginx-1.10.3.版本)
tar xvf nginx-1.10.3.tar.gz
cd nginx-1.10.3
./configure --user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_modulecurl

make && make installtcp

#3.1 建立軟連接文件
ln -s /usr/local/nginx/sbin/nginx /sbin/nginx
#顯示nginx命令幫助信息
nginx -hide

#4. 啓動:
#檢測配置文件語法
nginx -t
#啓動nginx服務
nginx測試

查看命令幫助:
/usr/local/nginx/sbin/nginx  -h
-v      查看nginx版本
-V      查看編譯參數 
-t      測試默認配置文件
-c      加載非默認位置配置文件
-s     指定操做信號,如restart、reload、stop、quit等。
如nginx   -s  stop中止nginx服務
  1. 查看啓動狀態:
    # ps aux | grep nginx
    root 8416 0.0 0.1 5760 660 ? Ss 23:29 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    nginx 8417 0.0 0.1 5904 992 ? S 23:29 0:00 nginx: worker process網站

    # netstat -ntlp | grep 80
    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8416/nginx.confui

  2. 測試主頁是否能夠訪問:
    # links 127.0.0.1 //若是顯示Welcome to nginx! 則說明服務正常

練習:在nginx服務器上建立新的測試網頁nginx.html,作本地訪問測試。echo 'nginx test page.' > /usr/local/nginx/html/nginx.htmlcurl 127.0.0.1/nginx.html 顯示出'nginx test page.'就說明網站服務正常

相關文章
相關標籤/搜索