精品軟體與實用教程
nginx網址:http://nginx.org/
如果你沒有設定過centos系統的初始環境,需要手動安裝Nginx需要的軟體包。
nginx的一些模組依賴一些lib庫,所以在安裝nginx之前,必須先安裝這些lib庫:包括PCRE正則表達式,安全套接字層密碼庫,和一些常用軟體包等等。如果之前搭建過環境,下面的請無視,直接下一步。
yum install gcc gcc-c++ yum -y install pcre pcre-devel yum install zlib zlib-devel yum install openssl openssl--devel yum make wget
下載最新版本的Nginx1.17.8
wget http://nginx.org/download/nginx-1.17.8.tar.gz
tar -zxvf nginx-1.17.8.tar.gz cd nginx-1.17.8
取消Debug編譯模式
vim auto/cc/gcc
#CFLAGS="$CFLAGS -g" 將這句話用#號註解掉。
編譯安裝
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
make make install
測試安裝是否成功:
cd /usr/local/nginx/sbin
進入nginx目錄輸入./nginx -t 或/usr/local/nginx/sbin/nginx -t
設定開機自啟動Nginx:
vi /lib/systemd/system/nginx.service
建立一個nginx.service文件
[Unit] Description=nginx - high performance web server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/inx/ ExecStop=/usr/local/nginx/sbin/nginx -s stop [Install] WantedBy=multi-user.target
設定nginx開機啟動,使設定生效:
systemctl enable nginx.service
編輯和設定nginx,開啟Nginx的設定文件
vi /usr/local/nginx/conf/nginx.conf
將下面程式碼替換掉nginx.conf檔案內的程式碼.這只是一個簡單的支援http存取和PHP存取的設定檔。
user www; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 6; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary> 網址; client_max_body_size 10M; root /var/www/; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php$is_args$args; } louded. fastcgi.conf; fastcgi_pass 127.0.0.1:9000; } } }
啟動Nginx
systemctl start nginx
在伺服器的VAR目錄下建立WWW目錄,然後在WWW目錄裡新建一個index.php的文件,將下列內容複製貼上到index.php後,儲存!
/var/www目錄是上面我們設定Nginx的網站存取檔案。這個目錄一定要跟nginx.conf裡設定的對應,可以隨便設定!
phpinfo();
?>
儲存好index.php後,輸入伺服器的IP位址,或是設定綁定的域名,網域一定要解析生效後才可以使用。
在瀏覽器輸入IP或網域後,就可以開啟PHP的探針頁面了。
在探針頁面上,你可以查看到安裝PHP的一些軟體包資訊和安裝目錄等內容。好了支援PHP的Nginx安裝好了!接下來就去安裝其它軟體吧!
下面是Nginx的控制指令:
systemctl start nginx 啟動
systemctl stop nginx 停止
systemctl reload nginx 重啟可以不用停止nginx服務,使修改的設定生效
systemctl restart nginx 重啟
systemctl enable nginx 設定開機啟動
systemctl disable nginx 停用開機啟動
systemctl status nginx 查看服務狀態