当前位置: 首页 > Linux

centos8的nginx安装步骤

时间:2023-04-06 03:43:45 Linux

1.这一步只适用于centos8首先查看自己的版本:查看号cat/etc/redhat-release2.安装编译工具和库文件makegcc-c++compileusingzlibzlib-develgzipinnginxuseopensslopenssl-develnginx支持https使用(即在ssl协议上传输http)执行命令:yum-yinstallmakezlibzlib-develgcc-c++libtoolopensslopenssl-devel3。安装PCRE(功能:让Nginx支持Rewrite功能)yuminstall-ypcrepcre-devel4下载nginx稳定版下载地址:http://nginx.org/download/nginx-1.18.0.tar.gz[root@localhost~]#mkdir/home/work/nginx[root@localhost~]#cd/home/work/nginx/[root@localhostnginx]#wgethttp://nginx.org/download/nginx-1.18.0。tar.gz--2020-05-2623:42:49--http://nginx.org/download/nginx-1.18.0.tar.gz正在解析nginx.org(nginx.org)...62.210。92.35,95.211.80.227,2001:1af8:4060:a004:21::e3正在连接nginx。org(nginx.org)|62.210.92.35|:80...connected.HTTP请求发送,等待响应...200OKLength:1039530(1015K)[application/octet-stream]Savingto:'nginx-1.18.0.tar.gz'nginx-1.18.0.tar.gz100%[===========================================>]1015K8.40KB/sin2m3s2020-05-2623:44:53(8.27KB/s)-'nginx-1.18.0.tar.gz'saved[1039530/1039530]5.解压[root@localhostnginx]#tarzxfnginx-1.18.0.tar.gz[root@localhostnginx]#lltotal1016drwxr-xr-x810011001158Apr2122:09nginx-1.18.0-rw-r--r--1rootroot1039530Apr2122:33nginx-1.18.0.tar.gz[root@localhostnginx]#6.编译安装指定编译安装目录--prefix=/home/work/nginx监控模块--with-http_stub_status_moduleSSL模块--with-http_ssl_module模块[root@localhostnginx]#cdnginx-1.18.0[root@localhostnginx-1.18.0]#./configure--prefix=/home/work/nginx--with-http_stub_status_module--with-http_ssl_module配置摘要+使用系统PCRE库+使用系统OpenSSL库+使用系统zlib库nginx路径前缀:“/home/work/nginx”nginx二进制文件:“/home/work/nginx/sbin/nginx”nginx模块路径:“/home/work/nginx/modules"nginx配置前缀:"/home/work/nginx/conf"nginx配置文件:"/home/work/nginx/conf/nginx.conf"nginxpid文件:“/home/work/nginx/logs/nginx.pid”nginx错误日志文件:“/home/work/nginx/logs/error.log”nginxhttp访问日志文件:“/home/work/nginx/logs/access.log"nginxhttp客户端请求主体临时文件:"client_body_temp"nginxhttp代理临时文件:"proxy_temp"nginxhttpfastcgi临时文件:"fastcgi_temp"nginxhttpuwsgi临时文件:"uwsgi_temp"nginxhttpscgi临时文件:"scgi_temp"[root@localhostnginx-1.18.0]#make[root@localhostnginx-1.18.0]#makeinstall完成后查看nginx版本/home/work/nginx/sbin/nginx-v7.配置systemctl管理[root@localhost~]#vi/etc/systemd/system/nginx.service[root@localhost~]#[root@localhost~]#cat/etc/systemd/system/nginx.service[Unit]Description=nginxAfter=syslog.targetnetwork.targetremote-fs.targetnss-lookup.target[Service]Type=oneshotExecStart=/home/work/nginx/sbin/nginxExecStop=/home/work/nginx/sbin/nginx-sstopExecReload=/bin/kill-sHUP$MAINPIDRemainAfterExit=yes[Install]WantedBy=multi-user.target[root@localhost~]#最后是其他相关命令:nginxreload配置文件/home/work/nginx/sbin/nginx-sreloadrestart/home/work/nginx/sbin/nginx-sreopenstop/home/work/nginx/sbin/nginx-sstop遇到的问题是makeinstall可能会报错,因为安装路径不是空文件夹。此时需要将编译路径设置为空文件夹。/configure--prefix="空文件夹路径"--with-http_stub_status_module--with-http_ssl_module然后重新执行上述过程最后看看效果:systemctlstatusnginx.servicecurl127.0.0.1