首页 > 系统相关 >Nginx安装部署

Nginx安装部署

时间:2023-03-23 17:12:52浏览次数:48  
标签:node 00 nginx 部署 root etc Nginx master 安装

title: Nginx安装部署
date: 2022-10-26
tags:
  - Linux
  - Nginx
categories: 
- 运维
- Nginx
keywords: 'Linux,Nginx'
description: Nginx安装部署
cover: https://qiufuqi.gitee.io/img/hexo/20221026153151.png
abbrlink: nginx_install
comments: false

Linux环境中安装nginx(1.20.2),系统版本centos7.6
Nginx 1.20.2 安装
安装方式如下:

YUM安装

yum安装:官方源安装,epol安装 二选一

添加YUM源

官方源安装
链接: http://nginx.org/en/linux_packages.html#RHEL-CentOS 可以对照自己的系统进行添加

[root@master-node ~]# vi /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

epol安装 (不建议,只能默认版本)

[root@master-node ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

加载yum包

[root@master-node ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras nginx-stable updates
Cleaning up list of fastest mirrors
Other repos take up 609 k of disk space (use --verbose for details)
[root@master-node ~]# yum makecache

安装指定版本

[root@master-node ~]# yum list nginx --showduplicates
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.nju.edu.cn
 * extras: mirrors.nju.edu.cn
 * updates: mirrors.nju.edu.cn
Available Packages
nginx.x86_64           1:1.8.0-1.el7.ngx              nginx-stable
·········
nginx.x86_64           1:1.20.1-1.el7.ngx             nginx-stable
nginx.x86_64           1:1.20.2-1.el7.ngx             nginx-stable
nginx.x86_64           1:1.22.0-1.el7.ngx             nginx-stable

[root@master-node ~]# yum -y install nginx-1.20.2-1.el7.ngx

查看版本

[root@master-node ~]# nginx -v
nginx version: nginx/1.20.2
[root@master-node ~]# rpm -qi nginx
Name        : nginx
Epoch       : 1
Version     : 1.20.2
·········
nginx [engine x] is an HTTP and reverse proxy server, as well as
a mail proxy server.

启动nginx

启动nginx 和 开机自启

[root@master-node ~]# systemctl start nginx
[root@master-node ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

默认配置

[root@master-node ~]# rpm -qc nginx
/etc/logrotate.d/nginx
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/mime.types
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params

基本操作

# 检测nginx配置是否正确
[root@master-node ~]# nginx -t
nginx: the configuration file /etc/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/conf/nginx.conf test is successful

# 查看nginx进程 并实现不中断服务加载配置
[root@master-node ~]# ps -ef|grep nginx
root     12483     1  0 15:52 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx    12484 12483  0 15:52 ?        00:00:00 nginx: worker process
nginx    12485 12483  0 15:52 ?        00:00:00 nginx: worker process
nginx    12486 12483  0 15:52 ?        00:00:00 nginx: worker process
nginx    12487 12483  0 15:52 ?        00:00:00 nginx: worker process
root     12553 12296  0 15:56 pts/0    00:00:00 grep --color=auto nginx
[root@master-node ~]# kill -HUP 12483   

[root@localhost ~]# rpm -Uvh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.18.0-1.el7.ngx.x86_64.rpm // rpm方式升级并安装某个版本的Nginx

编译安装

编译安装优势

  • 能够实现定制功能,需要什么功能就可以使用参数加上
  • 可以指定安装的路径

获取安装包

下载安装包并解压

[root@slave-node opt]# wget http://nginx.org/download/nginx-1.20.2.tar.gz
[root@slave-node opt]# tar -zxvf nginx-1.20.2.tar.gz

安装依赖包

[root@slave-node opt]# yum -y install pcre-devel zlib-devel gcc gcc-c++ make

创建用户、组

[root@slave-node opt]# useradd -M -s /sbin/nologin nginx

编译安装

安装路径/etc/nginx

[root@slave-node nginx-1.20.2]# cd /opt/nginx-1.20.2
[root@slave-node nginx-1.20.2]# ./configure --help
--with-http_ssl_module # 配置HTTPS时使用
--with-http_v2_module # 配置GOLANG语言时使用
--with-stream # 启用TCP/UDP代理服务

[root@slave-node nginx-1.20.2]# ./configure --prefix=/etc/nginx --user=nginx --group=nginx --with-http_stub_status_module

./configure \
--prefix=/etc/nginx \				#指定nginx的安装路径
--user=nginx \										#指定用户名
--group=nginx \										#指定组名
--with-http_stub_status_module						#启用 http_stub_status_module 模块以支持状态统计

[root@slave-node nginx-1.20.2]# make && make install

#让系统识别nginx的操作命令
[root@slave-node nginx-1.20.2]# ln -s /etc/nginx/sbin/nginx /usr/local/sbin/

添加系统服务

[root@slave-node nginx]# vi /lib/systemd/system/nginx.service

[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/etc/nginx/logs/nginx.pid
ExecStart=/etc/nginx/sbin/nginx
ExecrReload=/bin/kill -s HUP $MAINPID
ExecrStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

#赋权,除了root以外的用户都不能修改
[root@slave-node nginx]# chmod 754 /lib/systemd/system/nginx.service

启动nginx

启动nginx 和 开机自启

[root@master-node ~]# systemctl start nginx
[root@master-node ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

常见错误

  • ./configure: error: the HTTP rewrite module requires the PCRE library.
yum install pcre pcre-devel -y	
  • ./configure: error: SSL modules require the OpenSSL library.
yum install openssl openssl-devel -y 

标签:node,00,nginx,部署,root,etc,Nginx,master,安装
From: https://www.cnblogs.com/qiufuqi/p/17248163.html

相关文章

  • Keepalived安装部署
    title:Keepalived安装部署date:2022-10-22tags:-Linux-keepalivecategories:-运维-Nginx-keepalivedkeywords:'Linux,keepalived'cover:https://q......
  • 项目http请求部署到线上被自动转换为了https请求导致获取不到资源
    静态资源路径应该是http开头,访问的时候变成了https开头,导致找不到资源。原因是index.html的一项默认配置,注释掉就好了......
  • 源码安装nginx,平滑升级nginx,nginx认证和访问控制
    Nginx是俄罗斯人编写的十分轻量级的HTTP服务器是一个高性能的HTTP和反向代理服务器,同时也是一个IMAP/POP3/SMTP代理服务器【官方网站:http://nginx.org】源码安装Nginx#......
  • 安装宝塔面板
    宝塔面板一、安装宝塔面板2分钟装好面板,一键管理服务器,集成LAMP/LNMP环境安装,网站、FTP、数据库、文件管理、软件安装等功能宝塔面板下载,免费全能的服务器运维软件(bt.......
  • docker安装seata1.4.2
    dockerrun-d--restart=always--nameseata-p8091:8091-v/root/seata/seata-server:/seata-server-eSEATA_IP=127.0.0.1-eSEATA_PORT=8091seataio/seata-serv......
  • 安装 npm 包时无法解决 Angular 中的依赖树错误
    转载:https://www.angularjswiki.com/angular/unable-to-resolve-dependency-tree-error-in-angular-while-installing-npm-packages/修复Unabletoresolvedependency......
  • hydra安装——AttributeError: module ‘hydra‘ has no attribute ‘main‘
    AttributeError:module‘hydra’hasnoattribute‘main’问题1.使用如下方法安装hydra,pipinstallhydra,运行后报错AttributeError:module'hydra'hasnoattribute......
  • 宝塔在docker环境下 部署spring boot乱码
    1.docker在linux下面启动的时候,默认编码是POSIX通过locale可以查看具体的编码   那么我们可以设置,需要在容器中vi/root/.bashrc设置环境变量:exportLANG=en_US.......
  • 安装纯净windows10操作系统
    有些同学的个人电脑时间长了就会出现卡顿,蓝屏现象,工作、学习受到很大的困扰,自己重新安装windows系统怕中毒或是安装的不是纯净版,自带很多流氓软件等等。现在我来教大家用最......
  • centos7 Linux 安装及升级node、npm
    centos7初始版本node6npm3 更新升级node版本#安装nnpminstall-gn#查看版本n--version//v9.0.1#把当前系统的Node更新成最新的“稳定版本”nstabl......