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
    
相关文章
|
15天前
|
资源调度 JavaScript 搜索推荐
Linux系统之部署envlinks极简个人导航页
【4月更文挑战第11天】Linux系统之部署envlinks极简个人导航页
55 2
|
2天前
|
JavaScript 前端开发 应用服务中间件
angular引入包、路由权限配置、打包问题与nginx配置问题(简单部署)
angular引入包、路由权限配置、打包问题与nginx配置问题(简单部署)
9 0
|
4天前
|
5G Python
Windows11搭建Python环境(Anaconda安装与使用)
Windows11搭建Python环境(Anaconda安装与使用)
22 0
|
4天前
|
人工智能 安全 机器人
AI电销机器人系统源码部署:freeswitch安装Windows
在Windows上安装FreeSWITCH:访问官网下载安装程序,运行并按提示安装;选择安装路径和组件;等待安装完成;配置FreeSWITCH,修改设置;启动服务;测试其功能;如遇问题,参考官方文档或进行调试故障排除。记得定期更新维护以保证稳定安全。
|
4天前
|
Ubuntu Linux 测试技术
Linux(32)Rockchip RK3568 Ubuntu22.04上部署 Docker: 详细配置与功能测试(下)
Linux(32)Rockchip RK3568 Ubuntu22.04上部署 Docker: 详细配置与功能测试
35 1
|
5天前
|
资源调度 JavaScript Ubuntu
Linux系统之部署briefing视频聊天系统
【4月更文挑战第21天】Linux系统之部署briefing视频聊天系统
40 2
|
7天前
|
Apache 数据安全/隐私保护 Windows
如何在Windows部署TortoiseSVN客户端并实现公网连接内网VisualSVN服务端
如何在Windows部署TortoiseSVN客户端并实现公网连接内网VisualSVN服务端
|
7天前
|
存储 安全 文件存储
Windows系统本地部署HFS并结合内网穿透实现公网访问本地存储文件
Windows系统本地部署HFS并结合内网穿透实现公网访问本地存储文件
Windows系统本地部署HFS并结合内网穿透实现公网访问本地存储文件
|
10天前
|
应用服务中间件 Linux 开发工具
如何在阿里云服务器快速搭建部署Nginx环境
以下是内容的摘要: 本文档主要介绍了在阿里云上购买和配置服务器的步骤,包括注册阿里云账号、实名认证、选择和购买云服务器、配置安全组、使用Xshell和Xftp进行远程连接和文件传输,以及安装和配置Nginx服务器的过程。在完成这些步骤后,你将能够在服务器上部署和运行自己的网站或应用。
|
12天前
|
SQL 监控 安全
Linux&Windows 日志分析 陇剑杯 CTF
Linux&Windows 日志分析 陇剑杯 CTF