Centos7安装nginx

检查是否安装过

如果运行中就kill -9 进程ID

如果存在就rm -rf 文件名

  • 安装依赖

#安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境
yum install gcc-c++


#pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式,所以需要安装pcre库
yum install -y pcre pcre-devel


#zlib库提供了很多种压缩和解压缩方式nginx使用zlib对http包的内容进行gzip,所以需要安装
yum install -y zlib zlib-devel


#nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库
yum install -y openssl openssl-devel

  • 下载nginx

nginx: download

通过SSH工具上传

或者直接wget下载,右键复制下载链接

https://nginx.org/download/nginx-1.24.0.tar.gz

  • 解压

tar -zxvf nginx-1.24.0.tar.gz

进入根目录,配置安装目录

make /nginx

./configure --prefix=/nginx

  • 编译安装

 先编译make,再安装make install

  • 开放端口

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

  • 启动nginx

  • 配置开机自启

vim /etc/systemd/system/nginx.service

或者

vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=Nginx Server
After=nginx.service

[Service]
User=root
Group=root
Type=forking
ExecStart=/nginx/sbin/nginx -c /nginx/conf/nginx.conf
ExecStop=/nginx/sbin/nginx -s quit
ExecReload=/nginx/sbin/nginx -s reload
Restart=on-failure
PrivateTmp=true

[Install]
WantedBy=multi-user.target

重载

systemctl daemon-reload
systemctl start nginx.service;ps -ef | grep nginx
systemctl enable nginx.service
 

用yarn install后yarn build生成dish文件夹,压缩dish为dish.zip,通过ssh工具传到生产环境,通过unzip工具解压到nginx/html

然后vim /nginx/conf/nginx/conf(这个路径要看自己的)

server {
        listen       8091;
        server_name  localhost;

        #charset koi8-r;
        #开启gizp压缩
        gzip on;
        #>=100字节的文件进行gizp压缩
        gzip_min_length 100;
        #指定允许被压缩的MIME文件类型
        gzip_types text/plain text/css application/xml application/javascript
        #有的客户端不支持gizp压缩,提高兼容性
        gzip_vary on;

        #access_log  logs/host.access.log  main;

        location / {
            root   /nginx/html;
            index  index.html index.htm;
        }
}

开放8091端口,并重启nginx

此时就能访问

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值