正反代理-nginx安装

参考文章:https://www.cnblogs.com/ysocean/p/9384877.html

先预祝一下成功

废话不多说,开始吧,步骤不多

下载地址

https://nginx.org/en/download.html

鉴于为什么使用直接下载呢,因为我命令行下载一直失败,属于是迫不得已了...

我下载的是这个

下载完成后就上传到了服务器

接下来就是解压他 tar -zxvf nginx-1.26.3.tar.gz

必备环境

复制代码
1 yum install gcc-c++ # 编译依赖gcc环境
2 yum install -y pcre pcre-devel # nginx的http模块使用pcre来解析正则表达式
3 yum install -y zlib zlib-devel # nginx使用zlib对http包的内容进行gzip
4 yum install -y openssl openssl-devel # OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议,还支持https

编译安装

进入解压的nginx根目录

复制代码
1 ./configure --prefix=/usr/local/nginx
2 make
3 make install
# 注意:指定 /usr/local/nginx 为nginx 服务安装的目录。

启动

命令: /usr/local/nginx/sbin/nginx

访问:http://<你的服务器IP>

不出意外的话,你就成功啦

检查nginx是否运行【可选】

ps -ef | grep nginx

配置自启动【可选】

复制代码
vim /etc/systemd/system/nginx.service

# 输入以下内容
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
Restart=on-failure

[Install]
WantedBy=multi-user.target

重新加载: systemctl daemon-reload

启用并启动:

复制代码
systemctl enable nginx
systemctl start nginx

检查服务状态:systemctl status nginx