Linux安装nginx并配置ssl

linux下安装nginx,首先需要安装 gcc-c++编译器。然后安装nginx依赖的pcrezlib包。最后安装nginx即可。

1.先安装gcc-c++编译器

yum install gcc-c++
yum install -y openssl openssl-devel

2.再安装pcre包

yum install -y pcre pcre-devel

3.再安装zlib包

yum install -y zlib zlib-devel

下面进行nginx的安装

1.在/usr/local/下创建文件nginx文件

mkdir /usr/local/nginx

2.在网上下nginx包上传至Linux(https://nginx.org/download/),也可以直接下载

cd /usr/local/nginx
wget https://nginx.org/download/nginx-1.19.9.tar.gz

3.解压并进入nginx目录

tar -zxvf nginx-1.19.9.tar.gz
cd nginx-1.19.9

4.使用nginx默认配置

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-stream    #配置ssl

5.编译安装

make
make install

6.查找安装路径

whereis nginx

7.修改默认启动端口并配置读取其他nginx配置文件

vi /usr/local/nginx/conf/nginx.conf

在这里插入图片描述
在这里插入图片描述

8.自定义配置文件

vi /usr/local/nginx/conf/myconf/front.conf
server {
    listen 8020;  #启动端口
    server_name www.littlemantou.cn 150.158.146.22;  #配置域名
    ssl_certificate /opt/workplan/ssl/workplan.crt;  #配置证书
    ssl_certificate_key /opt/workplan/ssl/workplan.key;  #配置证书
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    #client_max_body_size 100m;
    
    root /opt/workplan/front/dist;  #配置静态文件路径
    index index.html;
    
    location / {
        try_files $uri $uri/ /index.html;
    }   
    
    
    location /prod-api/{
        client_max_body_size 100m;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:8090/;    #配置后端服务地址
    }
    access_log  /opt/workplan/front/log.log;
    error_log  /opt/workplan/front/error.log;   
}

9.进入sbin目录,可以看到有一个可执行文件nginx,直接./nginx执行就OK了。

./nginx

10.查看是否启动成功

ps -ef | grep nginx

在这里插入图片描述

11.杀掉nginx进程

pkill -9 nginx
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值