nginx的编译安装(详细步骤)

2023-12-30 08:18:33

systemctl stop firewalld
systemctl disable firewalld
setenforce 0

2、安装依赖包
yum -y install gcc pcre-devel openssl-devel zlib-devel openssl openssl-devel

3、创建运行用户、组
(Nginx 服务程序默认以 nobody 身份运行,建议为其创建专门的用户账号,以便更准确地控制其访问权限)
useradd -M -s /sbin/nologin nginx

4、编译安装Nginx
cd /opt
tar zxvf nginx-1.22.0.tar.gz -C /opt/

cd nginx-1.22.0/
./configure --prefix=/usr/local/nginx
–user=nginx
–group=nginx
–with-http_ssl_module
–with-http_v2_module
–with-http_realip_module
–with-http_stub_status_module
–with-http_gzip_static_module
–with-pcre
–with-stream
–with-stream_ssl_module
–with-stream_realip_module

make && make install

chown -R nginx.nginx /usr/local/nginx #修改权限

ln -s /usr/local/nginx/sbin/nginx /usr/sbin/ #让系统识别nginx的操作命令

vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/run/nginx.pid
#注意文件位置,如果不对 启动不了
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
#注意启动文件位置
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target

mkdir -p /usr/local/nginx/run/
#创建目录

vim /usr/local/nginx/conf/nginx.conf
#修改配置文件
pid /usr/local/nginx/run/nginx.pid;
#找到 pid的位置修改

systemctl daemon-reload
#重新加载配置

systemctl start nginx.service

vim /usr/local/nginx/html/index.html
100 dd 删除原内容

添加新内容:
this is zpll!

打开浏览器,访问ip地址

文章来源:https://blog.csdn.net/m0_65299341/article/details/135213225
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。