CentOS8如何安裝Nginx?
方式一:yum安裝
安裝:
yum install nginx
啟用并啟動Nginx服務:
sudo systemctl enable nginx
sudo systemctl start nginx
sudo systemctl stop nginx
要驗證服務是否正在運行,檢查其狀態:
sudo systemctl status nginx
方式二:自定義目錄安裝1.安裝工具和庫
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
# PCRE是一個Perl庫,包括 perl 兼容的正則表達式庫。nginx 的 http 模塊使用 pcre 來解析正則表達式# zlib庫提供了很多種壓縮和解壓縮的方式, nginx 使用 zlib 對 http 包的內容進行 gzip2.下載并解壓nginx
wget -c https://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
1.configure1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_sub_module --with-http_gzip_static_module --with-pcre
#--prefix 指定安裝路徑#--with-http_stub_status_module 允許查看nginx狀態的模塊# --with-http_ssl_module 支持https的模塊執行成功后顯示的文件路徑:Configuration summary+ using system PCRE library+ using system OpenSSL library+ using system zlib librarynginx 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"2.編譯并安裝make && make install
進入到安裝nginx目錄下面的sbin啟動命令./nginx打開瀏覽器訪問你的IP地址,顯示此頁面說明nginx啟動成功。其他命令:./nginx -s quit: (溫和)此方式停止步驟是待nginx進程處理任務完畢進行停止。 ./nginx -s stop: (強硬)此方式相當于先查出nginx進程id再使用kill命令強制殺掉進程。./nginx -s reload 重啟nginx(不推薦此方法,推薦先停止在啟動)