Centos7.9安装Nginx

1、Nginx下载(可更换其他版本)

wget http://nginx.org/download/nginx-1.19.10.tar.gz

2、查看gcc版本

gcc -v

3、如果没有gcc,则安装

yum install -y gcc

4、安装nginx所需要的依赖

yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel

5、解压nginx安装包

tar -zxvf nginx-1.19.10.tar.gz

6、进入安装包目录

cd nginx-1.19.10

7、配置

./configure --prefix=/usr/tools/nginx \
--pid-path=/usr/tools/nginx/log/nginx.pid \
--lock-path=/usr/tools/nginx/log/nginx.lock \
--error-log-path=/usr/tools/nginx/log/error.log \
--http-log-path=/usr/tools/nginx/log/access.log \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--without-http-cache \
--with-http_ssl_module \
--with-http_realip_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

8、编译并安装

make && make install

9、测试是否安装成功

/usr/tools/nginx/sbin/nginx -t

10、创建nginx所需要的目录

mkdir -p /var/temp/nginx

11、修改nginx.conf配置文件

#user  root;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    include conf.d/*.conf;
    client_max_body_size 5M;

    sendfile        on;

    keepalive_timeout  65;
}

12、配置nginx子配置文件

server {
    listen 443 ssl;
    server_name ${域名 || 地址};

    ssl_certificate /usr/tools/nginx/cert/证书.pem;
    ssl_certificate_key /usr/tools/nginx/cert/证书.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;

    root /home/web/;

    location / {
        root /home/web/test;
        index index.html index.htm;
        try_files $uri $uri/ @resume-router;
    }

    location @resume-router {
        rewrite ^.*$ /index.html last;
    }

    error_page   403 404 500 502 503 504  /error.html;
    location = /error.html {
        root   html/error;
    }
}

server {
    listen 80;
    server_name ${域名 || 地址};
    return 301 https://${域名 || 地址};
}

13、配置开机自启

cd /usr/lib/systemd/system/

14、编写nginx启动项配置

vim nginx.service

15、修改配置文件

[Unit]
Description=nginx
After=network.target
  
[Service]
Type=forking
ExecStart=/usr/tools/nginx/sbin/nginx -c /usr/tools/nginx/conf/nginx.conf
ExecReload=/usr/tools/nginx/sbin/nginx -s reload -c /usr/tools/nginx/conf/nginx.conf
ExecStop=/usr/tools/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target

16、设置开机自启动

systemctl enable nginx

17、基本用法

systemctl status nginx      # 查看状态
systemctl start nginx      # 启动
systemctl stop nginx      # 停止
systemctl restart nginx      # 重启
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MajorRoss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值