Linux安装Nginx方法

创建安装目录

[root@localhost ~]# mkdir -p /appdata/nginx 

安装依赖环境

[root@localhost nginx]# yum -y install wget gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

说明:gcc源码编译, pcre-devel 安装,nginx 的 http 模块使用 pcre 来解析正则表达式,zlib安装,nginx 使用zlib对http包的内容进行gzip,OpenSSL 安装,强大的安全套接字层密码库,nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http)

从官网地址获取安装包:
https://nginx.org/en/download.html
在这里插入图片描述
右键复制链接地址,wget方式获取

[root@localhost ~]# wget -c https://nginx.org/download/nginx-1.18.0.tar.gz

解压

[root@localhost ~]# tar -zxvf nginx-1.18.0.tar.gz && cd nginx-1.18.0

新建log日志文件

[root@localhost nginx-1.18.0]# mkdir -p /applog/nginx/ && mkdir -p /var/temp/nginx/clien && touch  /applog/nginx/error.log && touch  /applog/nginx/access.log 

添加配置安装

./configure \
--prefix=/appdata/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/applog/nginx/error.log \
--http-log-path=/applog/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-file-aio \
--with-http_realip_module

编译安装

[root@localhost nginx-1.18.0]# make && make install

切换目录

[root@localhost nginx-1.18.0]# cd /appdata/nginx/sbin

启动

[root@localhost sbin]# ./nginx

防火墙端口添加

[root@localhost sbin]#sudo firewall-cmd --add-port=80/tcp --permanent && sudo firewall-cmd --reload

访问服务器ip地址,出现以下信息
在这里插入图片描述

停止

[root@localhost sbin]# ./nginx -s stop

重新启动

[root@localhost sbin]# ./nginx -s reload

添加systemctl启动方式

[root@localhost sbin]# vi /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=/var/run/nginx/nginx.pid
ExecStart=/appdata/nginx/sbin/nginx -c /appdata/nginx/conf/nginx.conf
ExecStartPre=/appdata/nginx/sbin/nginx -t
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

重载系统

[root@localhost sbin]# systemctl daemon-reload

添加开机自启动

[root@localhost sbin]# systemctl enable nginx

启动

[root@localhost sbin]# systemctl start nginx

重载配置

[root@localhost sbin]# systemctl reload nginx

关闭

[root@localhost sbin]# systemctl stop nginx
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值