简书: https://www.jianshu.com/p/5c3938ce2cf6
https://nginx.org/en/download.html
略
tar zxf nginx-1.21.6.tar.gz
cd nginx-1.21.6
编译并指定安装位置
./cofigure --prefix=/usr/local/nginx
错误解决
错误:"./configure: error: C compiler cc is not found" 解决:yum -y install gcc-c++
编译成功
nginx 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
make
make install
了解: configure, make, make install
https://www.cnblogs.com/python99/p/12242613.html
configure 这一步一般用来生成Makefile,为下一步的编译做准备,你可以通过在configure后加上参数来对安装进行控制,比如代码:./configure --prefix=/usr上面的意思是将谇软件安装在/usr下面,执行文件就会安装在/usr/bin,同时一些软件的配置文件你可以通过指定--sys-config=参数进行设定。有一些软件还可以加上--with, --enable, --without, --disable等参数对编译加以控制,你可以通过允许./configure --help查看详细的说明帮助。 make 这一步就是编译,大多数的源代码包都经过这一步进行编译,如果在make过程中出现error,可以向开发者提交bugreport(一般在install里有提交地址),或者你的系统少了一些依赖库等。make的作用是开始进行源代码编译,以及一些功能的提供,这些功能由它的Makefile设置文件提供相磁的功能。 make是Linux开发套件里面自动化编译的一个控制程序,他通过借助Makefile里面编写的编译规范进行自动化调用gcc、ld以及某些需要的程序进行编译的程序。 make install 进行安装(当然有些软件需要先运行make check或make test来进行一些测试)。如果原始代码编译无误,且执行结果正确,便可以把程序安装至系统预设的可执行文件存放路径。如果用bin_PROGRAMS宏的话,程序会被安装至/usr/local/bin这个目录,或者库文件拷贝到相应的目录下 make clean可以清除编译产生的可执行文件及目标文件。View Code
cd /usr/local/nginx cd sbin ./nginx
8.开启、关闭防火墙
systemctl start firewalld systemctl stop firewalld
# 防火墙放行端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
# 重启防火墙
firewalld-cmd --reload
https://www.cnblogs.com/goOJBK/p/15703960.html
vi /usr/lib/systemd/system/nginx.service
nginx.service
[Unit] Description=nginx - web server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop ExecQuit=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target
脚本操作
1.杀死进程
kill -quit <master pid>
2.重新加载nginx服务
systemctl daemon-reload nginx.service
3.启动,关闭,状态,进程
systemctl start nginx.service systemctl stop nginx.service systemctl status nginx.service systemctl status nginx ps -ef | grep nginx