windows+linux环境下nginx部署环境

简介: windows+linux环境下nginx部署环境

@[TOC]

一、将自己的电脑作为服务器,【照猫画虎可以在服务器上设置下载nginx】

Window下载nginx

1. 官方网站:

https://nginx.org/

2. 版本描述:

在这里插入图片描述

3. 下载稳定版

在这里插入图片描述

4. 下载解压到某文件夹下,注意路径尽量不要有中文名

在这里插入图片描述

5. 输入网址 localhost 进行访问

在这里插入图片描述

6. 将项目进行打包部署

6.1、打包 npm run build

将项目打包:npm run build,生成dist文件夹,打包前如需配置,tsconfig.jsonjsconfig.jspn需要设置,请参考:【待补充】
在这里插入图片描述

6.2、部署项目

在这里插入图片描述

==将dist文件夹下的内容拷贝至指定目录下==

在这里插入图片描述

6.3、更改nginx配置文件

  1. 修改配置文件 nginx-1.20.1\conf\nginx.config 文件

在这里插入图片描述

在这里插入图片描述
如下可做参考

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
   
   
    worker_connections  1024;
}


http {
   
   
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
   
   
        # 代表监听的端口号
        listen       8001;
        server_name  localhost;
        root         ./html/web/;
        index        index.html index.htm;






        location / {
   
   
            # 截取404 的 url,传给 @router
            try_files $uri $uri/   @router;
        }
        location /api/{
   
   
            # 项目中代理使用的api要转的地址
            proxy_pass http://192.168.1.31:8083/;
            proxy_redirect default;
            proxy_set_header Host $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;

        }
        location @router {
   
   
            # 接到截取的uri 并按一定规则重写 uri 和vue 路由跳转
            rewrite ^.*&    /index.html last;
        }






    }
}
  1. 更改完配置之后需要重新启动nginx

    • ==无脑式重启==
      在这里插入图片描述

      • ==或使用命令进行结束进程==

        # 启动:
        直接点击Nginx目录下的nginx.exe  或者 cmd 运行 start nginx
        
        # 关闭:
        nginx -s stop  或者  nginx -s quit
        
        stop 表示立即停止nginx,不保存相关信息
        quit 表示正常退出nginx,并保存相关信息
        
        # 重启:
        nginx -s reload
        
  2. 到此步骤就完成了项目在本地上的部署

二、项目在远程Linux下的部署

建议在Mac电脑上部署

1. 通过终端远程登录自己的服务器

ssh登录到远程主机上
ssh root@

2. 安装并启动 Nginx

  1. yum install nginx
  2. systemctl start nginx.service # 开启nginx服务
  3. systemctl enable nginx.service # 跟随系统启动
    在这里插入图片描述
  4. 上传打包项目部署
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    三、linux上离线安装nginx

    1.下载导入离线包

    链接:https://pan.baidu.com/s/1bXrHV6I0W6yYLo6elhyakA
    提取码:9e5w

2.安装依赖包

安装依赖包gcc,在gcc目录下执行以下命令:

rpm -Uvh *.rpm --nodeps --force

安装依赖包gcc-c++,在gcc-c++目录下执行以下命令:

rpm -Uvh *.rpm --nodeps --force

3.检测是否安装成功

gcc -v


g++ -v

在这里插入图片描述

版本可能不一样,但出现类似文字即可。

4.安装PCRE

在nginx目录下解压pcre并安装

tar -zxvf pcre-8.35.tar.gz
cd pcre-8.35
./configure
make
make install

5.安装libtool

在nginx目录下解压libtool 并安装

tar -zxvf libtool-2.4.2.tar.gz
cd libtool-2.4.2
./configure
make
make install

6.安装nginx

在nginx目录下解压nginx并安装

tar -zxvf nginx-1.13.9.tar.gz
cd nginx-1.13.9
./configure
make
make install

7. nginx命令

  • 首先找到nginx的安装目录

      which nginx
    

    在这里插入图片描述

  • 查看进程是否存在

      ps -ef|grep nginx
    

    在这里插入图片描述

  • 杀死进程

      kill -QUIT 1282
    
  • 强制停止

      kill -9 1282
    
  • 进入到nginx 的sbin 目录,启动nginx

      cd /usr/local/nginx/sbin/
      ./nginx             启动
      ./nginx -s stop     停止
      ./nginx -s quit     退出
      ./nginx -s reload   重启
      service nginx restart  如果启动没成功就选择这个命令
    
  • 保险起见,可以再看下进程,成功的情况,会看到新的进程号

      ps -ef|grep nginx
    
相关文章
|
4月前
|
安全 Linux 生物认证
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
197 0
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
|
4月前
|
安全 Linux 生物认证
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
263 17
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
|
4月前
|
SQL 安全 Linux
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
253 1
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
|
4月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
359 1
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
|
4月前
|
存储 Linux 开发工具
Linux环境下使用Buildroot配置软件包
使用Buildroot可以大大简化嵌入式Linux系统的开发和维护工作,但它需要对Linux系统和交叉编译有深入的理解。通过上述步骤,可以有效地配置和定制软件包,为特定的嵌入式应用构建高效、稳定的系统。
552 11
|
4月前
|
Linux 虚拟化 iOS开发
VMware Remote Console 13.0.1 for macOS, Linux, Windows - vSphere 虚拟机控制台的桌面客户端
VMware Remote Console 13.0.1 for macOS, Linux, Windows - vSphere 虚拟机控制台的桌面客户端
945 0
VMware Remote Console 13.0.1 for macOS, Linux, Windows - vSphere 虚拟机控制台的桌面客户端
|
数据采集 应用服务中间件 Linux
一篇文章教会你在Windows和Linux系统下搭建Nginx
一篇文章教会你在Windows和Linux系统下搭建Nginx
534 0
一篇文章教会你在Windows和Linux系统下搭建Nginx
|
5月前
|
编解码 应用服务中间件 Linux
centos配置nginx-rtmp实现ffmpeg转码rtsp为rtmp视频流
centos配置nginx-rtmp实现ffmpeg转码rtsp为rtmp视频流
533 1
|
9月前
|
应用服务中间件 Linux 网络安全
Centos 8.0中Nginx配置文件和https正书添加配置
这是一份Nginx配置文件,包含HTTP与HTTPS服务设置。主要功能如下:1) 将HTTP(80端口)请求重定向至HTTPS(443端口),增强安全性;2) 配置SSL证书,支持TLSv1.1至TLSv1.3协议;3) 使用uWSGI与后端应用通信(如Django);4) 静态文件托管路径设为`/root/code/static/`;5) 定制错误页面(404、50x)。适用于Web应用部署场景。
891 87