wordpress 修改邮箱,网站建设内部优化,桦甸市建设局网站,临猗做网站1.下载安装包
官网下载地址#xff1a;nginx: download 可以先将安装包下载到本地再传到服务器#xff0c;或者直接用wget命令将安装包下载到服务器#xff0c;这里我们直接将安装包下载到服务器上。未安装wget命令的需要先安装wget#xff0c;yum install -y wget
[root…1.下载安装包
官网下载地址nginx: download 可以先将安装包下载到本地再传到服务器或者直接用wget命令将安装包下载到服务器这里我们直接将安装包下载到服务器上。未安装wget命令的需要先安装wgetyum install -y wget
[rootreader app]# cd /usr/soft/
[rootreader soft]# wget -c https://nginx.org/download/nginx-1.24.0.tar.gz
--2023-11-03 22:35:48-- https://nginx.org/download/nginx-1.24.0.tar.gz
Resolving nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5704::6, ...
Connecting to nginx.org (nginx.org)|3.125.197.172|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1112471 (1.1M) [application/octet-stream]
Saving to: ‘nginx-1.24.0.tar.gz’nginx-1.24.0.tar.gz 100%[] 1.06M 1.45MB/s in 0.7s 2023-11-03 22:35:50 (1.45 MB/s) - ‘nginx-1.24.0.tar.gz’ saved [1112471/1112471][rootreader soft]# 解压安装包
[rootreader soft]# tar -xvf nginx-1.24.0.tar.gz 2.安装C语言编译环境及相关依赖
yum -y install gcc-c zlib zlib-devel openssl openssl-devel pcre pcre-devel3.执行./configure配置编译环境 如果我们要指定nginx的安装路径默认路径/usr/local/nginx或是需要添加相关nginx模块在./configure 命令后需要添加相关参数可以同时带多个参数。 可以使用 ./configure --help 命令查看相关参数/指令
[rootreader nginx-1.24.0]# ./configure --help--help print this message--prefixPATH set installation prefix--sbin-pathPATH set nginx binary pathname--modules-pathPATH set modules path--conf-pathPATH set nginx.conf pathname--error-log-pathPATH set error log pathname--pid-pathPATH set nginx.pid pathname--lock-pathPATH set nginx.lock pathname--userUSER set non-privileged user forworker processes--groupGROUP set non-privileged group forworker processes--buildNAME set build name--builddirDIR set build directory
..... 我这里需要添加 --with-threads --with-http_ssl_module --with-http_gzip_static_module大家根据个人需要进行添加如果首次安装未添加后续还是可以重新编译的见另一篇博文。
[rootreader nginx-1.24.0]# ./configure --prefix/usr/local/nginx --with-threads --with-http_ssl_module --with-http_gzip_static_module
4.编译安装nginx
make make install
5.将nginx命令添加到全局命令(按需设置)
[rootreader etc]# vim /etc/profile# /etc/profile# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc·····
export PATH$PATH:${JAVA_PATH}export MYSQL_HOME/usr/local/mysql
export PATH${MYSQL_HOME}/bin:${PATH}export PATH$PATH:/usr/local/nginx/sbin
添加完成后执行如下命令使配置生效
source /etc/profile
6.启动nginx
rootreader etc]# nginx
[rootreader etc]# ps -ef | grep nginx
root 7156 1 0 23:45 ? 00:00:00 nginx: master process nginx
nobody 7157 7156 0 23:45 ? 00:00:00 nginx: worker process
root 7161 4040 0 23:48 pts/0 00:00:00 grep --colorauto nginx如果未添加全局命令就进入安装目录的sbin目录下执行./nginx
[rootreader sbin]# cd /usr/local/nginx/sbin/
[rootreader sbin]# ./nginx
[rootreader sbin]# ps -ef | grep nginx
root 7175 1 0 Nov03 ? 00:00:00 nginx: master process ./nginx
nobody 7176 7175 0 Nov03 ? 00:00:00 nginx: worker process
root 7178 4040 0 00:00 pts/0 00:00:00 grep --colorauto nginx
[rootreader sbin]#
7.访问nginx
浏览器输入IP访问nginx如果现实下图说明配置并启动成功。 8.nginx 常用命令
[rootreader sbin]# nginx -h
nginx version: nginx/1.24.0
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix][-e filename] [-c filename] [-g directives]Options:-?,-h : this help-v : show version and exit # 查看版本号-V : show version and configure options then exit # 查看版本及配置-t : test configuration and exit # 检查配置文件是否有问题-T : test configuration, dump it and exit # 检查配置文件是否有问题并转储-q : suppress non-error messages during configuration testing-s signal : send signal to a master process: stop, quit, reopen, reload-p prefix : set prefix path (default: /usr/local/nginx/) #设置前缀路径(默认是:/usr/share/nginx/)-e filename : set error log file (default: logs/error.log) #设置/指定error_log输出位置默认位置安装目录下的 logs/error.log-c filename : set configuration file (default: conf/nginx.conf) #设置/指定配置文件配置文件默认配置文件在安装目录下的 conf/nginx.conf-g directives : set global directives out of configuration file #在配置文件之外设置全局指令[rootreader sbin]# -s signal 解释nginx -s reload # 重新加载配置文件关闭旧进程启用新进程
nginx -s reopen # 重新打开日志文件
nginx -s stop # 强制停止nginx
nginx -s quit # 等待所有请求都处理完后再关闭nginx 注意单独说明 nginx -s reopen命令执行该命令时nginx会先检查原日志文件error.log 或 access.log是否存在如果存在日志还是正常写入原文件中。如果原日志文件不存在或名称已修改这时nginx才会重新生成一个空日志文件并将日志写入。亲测结果。
[rootreader sbin]# cd ../logs/
[rootreader logs]# ll
total 12
-rw-r--r-- 1 nobody root 1890 Nov 4 00:37 access.log
-rw-r--r-- 1 nobody root 378 Nov 4 00:40 error.log
-rw-r--r-- 1 root root 5 Nov 3 23:59 nginx.pid
[rootreader logs]# nginx -s reopen ll
[1] 7320
total 12
-rw-r--r-- 1 nobody root 1890 Nov 4 00:37 access.log
-rw-r--r-- 1 nobody root 378 Nov 4 00:40 error.log
-rw-r--r-- 1 root root 5 Nov 3 23:59 nginx.pid
[rootreader logs]# nginx -s reopen ll
[2] 7322
total 12
-rw-r--r-- 1 nobody root 1890 Nov 4 00:37 access.log
-rw-r--r-- 1 nobody root 441 Nov 4 00:41 error.log
-rw-r--r-- 1 root root 5 Nov 3 23:59 nginx.pid
[1] Done nginx -s reopen
[rootreader logs]# nginx -s reopen ll
[3] 7324
total 12
-rw-r--r-- 1 nobody root 1890 Nov 4 00:37 access.log
-rw-r--r-- 1 nobody root 504 Nov 4 00:42 error.log
-rw-r--r-- 1 root root 5 Nov 3 23:59 nginx.pid
[2] Done nginx -s reopen
[rootreader logs]# mv error.log error_1.log ll
[4] 7330
total 12
-rw-r--r-- 1 nobody root 1890 Nov 4 00:37 access.log
-rw-r--r-- 1 nobody root 567 Nov 4 00:42 error_1.log
-rw-r--r-- 1 root root 5 Nov 3 23:59 nginx.pid
[3] Done nginx -s reopen
[4] Done mv -i error.log error_1.log
[rootreader logs]# ll
total 12
-rw-r--r-- 1 nobody root 1890 Nov 4 00:37 access.log
-rw-r--r-- 1 nobody root 567 Nov 4 00:42 error_1.log
-rw-r--r-- 1 root root 5 Nov 3 23:59 nginx.pid
[rootreader logs]# nginx -s reopen ll
[1] 7334
total 12
-rw-r--r-- 1 nobody root 1890 Nov 4 00:37 access.log
-rw-r--r-- 1 nobody root 567 Nov 4 00:42 error_1.log
-rw-r--r-- 1 root root 5 Nov 3 23:59 nginx.pid
[rootreader logs]# ll
total 16
-rw-r--r-- 1 nobody root 1890 Nov 4 00:37 access.log
-rw-r--r-- 1 nobody root 567 Nov 4 00:42 error_1.log
-rw-r--r-- 1 nobody root 63 Nov 4 00:43 error.log
-rw-r--r-- 1 root root 5 Nov 3 23:59 nginx.pid
[1] Done nginx -s reopen
[rootreader logs]#
[rootreader logs]# ll
total 16
-rw-r--r-- 1 nobody root 1890 Nov 4 00:37 access.log
-rw-r--r-- 1 nobody root 567 Nov 4 00:42 error_1.log
-rw-r--r-- 1 nobody root 63 Nov 4 00:43 error.log
-rw-r--r-- 1 root root 5 Nov 3 23:59 nginx.pid
[rootreader logs]# ll
total 16
-rw-r--r-- 1 nobody root 1890 Nov 4 00:37 access.log
-rw-r--r-- 1 nobody root 567 Nov 4 00:42 error_1.log
-rw-r--r-- 1 nobody root 63 Nov 4 00:43 error.log
-rw-r--r-- 1 root root 5 Nov 3 23:59 nginx.pid
[rootreader logs]#
[rootreader logs]#
[rootreader logs]# rm -rf access.log
[rootreader logs]# ll
total 12
-rw-r--r-- 1 nobody root 567 Nov 4 00:42 error_1.log
-rw-r--r-- 1 nobody root 63 Nov 4 00:43 error.log
-rw-r--r-- 1 root root 5 Nov 3 23:59 nginx.pid
[rootreader logs]# nginx -s reopen
[rootreader logs]# ll
total 12
-rw-r--r-- 1 nobody root 0 Nov 4 00:43 access.log
-rw-r--r-- 1 nobody root 567 Nov 4 00:42 error_1.log
-rw-r--r-- 1 nobody root 126 Nov 4 00:43 error.log
-rw-r--r-- 1 root root 5 Nov 3 23:59 nginx.pid
[rootreader logs]#
[rootreader logs]# mv access.log access_1.log
[rootreader logs]# ll
total 12
-rw-r--r-- 1 nobody root 0 Nov 4 00:43 access_1.log
-rw-r--r-- 1 nobody root 567 Nov 4 00:42 error_1.log
-rw-r--r-- 1 nobody root 126 Nov 4 00:43 error.log
-rw-r--r-- 1 root root 5 Nov 3 23:59 nginx.pid
[rootreader logs]# nginx -s reopen
[rootreader logs]#
[rootreader logs]# ll
total 12
-rw-r--r-- 1 nobody root 0 Nov 4 00:43 access_1.log
-rw-r--r-- 1 nobody root 0 Nov 4 00:44 access.log
-rw-r--r-- 1 nobody root 567 Nov 4 00:42 error_1.log
-rw-r--r-- 1 nobody root 189 Nov 4 00:44 error.log
-rw-r--r-- 1 root root 5 Nov 3 23:59 nginx.pid
[rootreader logs]# 9.设置nginx开机自启动 源码解压编译安装的需要手动在/lib/systemd/system目录下创建nginx.service文件。 nginx.service文件内容如下
[Unit]
Descriptionnginx service
Afternetwork.target [Service]
Typeforking
ExecStart/usr/local/nginx/sbin/nginx
ExecReload/usr/local/nginx/sbin/nginx -s reload
ExecStop/usr/local/nginx/sbin/nginx -s quit
PrivateTmptrue [Install]
WantedBymulti-user.target
上述文件各行解释说明
[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Typeforking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmpTrue表示给服务分配独立的临时空间
注意[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置可设置为多用户即系统运行级别为3 创建完成后执行如下命令设置开机启动。
systemctl enable nginx.service 查看开机启动项检查是否设置成功。
systemctl list-unit-files | grep nginx
[rootreader logs]# systemctl enable nginx.service
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[rootreader logs]#
[rootreader logs]#
[rootreader logs]#
[rootreader logs]# systemctl list-unit-files | grep nginx
nginx.service enabled
[rootreader logs]#
其它命令
启动nginx服务 : systemctl start nginx.service
停止nginx服务 : systemctl stop nginx.service
设置开机自启动 : systemctl enable nginx.service
停止开机自启动 : systemctl disable nginx.service
查看服务当前状态: systemctl status nginx.service
重新启动服务 : systemctl restart nginx.service
查看所有已启动服务:systemctl list-units --typeservice