nginx安裝啓動步驟(centos7環境):
1.需要安裝gcc環境,編譯c、c++代碼 yum -y install gcc gcc-c++ autoconf automake make
2.第三方的開發包 1 PERE PCRE(Perl Compatible Regular Expressions)是一個Perl庫,包括 perl 兼容的正則表達式庫。 nginx的http模塊使用pcre來解析正則表達式,所以需要在linux上安裝pcre庫。 注:pcre-devel是使用pcre開發的一個二次開發庫。nginx也需要此庫。 # yum install -y pcre pcre-devel
2 zlib
zlib庫提供了很多種壓縮和解壓縮的方式,nginx使用zlib對http包的內容進行gzip,所以需要在linux上安裝zlib庫。
# yum install -y zlib zlib-devel
3 openssl
OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、常用的密鑰和證書封裝管理功能及SSL協議,
並提供豐富的應用程序供測試或其它目的使用。
nginx不僅支持http協議,還支持https(即在ssl協議上傳輸http),所以需要在linux安裝openssl庫。
# yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel
3.安裝nginx 1.下載nginx最新包nginx-1.18.0.tar.gz 2.解壓nginx-1.18.0.tar.gz tar -zxvf nginx-1.18.0.tar.gz 3.進入nginx-1.18.0目錄 cd nginx-1.18.0 4.使用cofigure命令創建一個makeFile文件 ################################################################ ################################################################ ./configure
--prefix=/usr/local/nginx
--pid-path=/var/run/nginx/nginx.pid
--lock-path=/var/lock/nginx.lock
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--with-http_gzip_static_module
--http-client-body-temp-path=/var/temp/nginx/client
--http-proxy-temp-path=/var/temp/nginx/proxy
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi
--http-scgi-temp-path=/var/temp/nginx/scgi --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module ################################################################ ################################################################ 5.編譯和安裝nginx make && make install 6.啓動nginx cd /usr/local/nginx ./sbin/nginx
啓動報錯:
nginx: [emerg] mkdir() "/var/temp/nginx/client" failed (2: No such file or directory)
解決:
mkdir -p /var/temp/nginx
7.查看nginx是否啓動
ps -aux | grep nginx
8.重新加載nginx
./sbin/nginx -s reload
9.關閉nginx
./sbin/nginx -s stop
./sbin/nginx -s quit
10.訪問nginx
開放80端口
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-all