博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
centos安装nginx,部署vue项目
阅读量:2342 次
发布时间:2019-05-10

本文共 4491 字,大约阅读时间需要 14 分钟。

  • 参考:
  • 参考:
  • 参考:
  • 参考:  
  • 参考: 

centos安装nginx,部署vue项目

1、安装nginx依赖包

# 首先安装必要的库(nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库)yum install gcc-c++ -yyum install pcre pcre-devel -yyum install zlib zlib-devel -yyum install openssl openssl-devel -y

2、下载安装包和解压

# 安装之前,最好检查一下是否已经安装有nginxfind -name nginx# 如果系统已经安装了nginx,那么就先卸载yum remove nginx# 首先进入/usr/local目录cd /usr/local# 从官网下载最新版的nginxwget http://nginx.org/download/nginx-1.17.7.tar.gz# 解压nginx压缩包tar -zxvf nginx-1.17.7.tar.gz

3、开始安装

# 会产生一个nginx-1.17.7 目录,这时进入nginx-1.17.7目录cd  nginx-1.17.7# 接下来安装,使用--prefix参数指定nginx安装的目录,make、make install安装# --prefix 指定安装目录,默认为 /usr/local/nginx# --with-http_ssl_module 启用ssl模块./configure --with-http_ssl_modulemakemake install# 如果没有报错,顺利完成后,最好看一下nginx的安装目录whereis nginx# 安装完毕后,进入安装后目录(/usr/local/nginx)便可以启动或停止它了。# 到此,使用CentOS安装nginx已经完成了,其实看看还是蛮简单的。

4、启动

/usr/local/nginx/sbin/nginx# 检查是否启动成功:# 打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。# 如果运行的时候不带-c参数,那就采用默认的配置文件,即/usr/local/nginx/conf/nginx.conf# 查看运行进程状态:ps aux | grep nginx

5、其他命令

# 部分命令如下:# 重启:/usr/local/nginx/sbin/nginx –s reload# 停止:/usr/local/nginx/sbin/nginx –s stop# 测试配置文件是否正常:/usr/local/nginx/sbin/nginx –t# 强制关闭:pkill nginx

6、配置文件nginx.conf

#user  nobody;worker_processes  1;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    sendfile        on;    keepalive_timeout  65;    # 压缩    gzip  on;    server {        listen       80;        server_name  localhost;         location / {            root   html;            index  index.html index.htm;            # 强制跳转到https            rewrite ^(.*)$  https://$host$1 permanent;        }        # redirect server error pages to the static page /50x.html        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }    }    # HTTPS server    server {      listen       443 ssl;      server_name  localhost;	  # [ssl证书]      #ssl_certificate      /etc/letsencrypt/live/sdmp.makern.cn/fullchain.pem;      #ssl_certificate_key  /etc/letsencrypt/live/sdmp.makern.cn/privkey.pem;      ssl_session_cache    shared:SSL:1m;      ssl_session_timeout  5m;      ssl_ciphers  HIGH:!aNULL:!MD5;      ssl_prefer_server_ciphers  on;      location / {        root /opt/vue/dist2;        index  index.html index.htm;        try_files $uri $uri/ /index.html;      }      location /sdmp {        proxy_pass         https://localhost:8080/sdmp;        proxy_http_version 1.1;# http协议版本        proxy_set_header   Host $host;        proxy_set_header   Upgrade $http_upgrade;# websocket配置        proxy_set_header   Connection "Upgrade";# websocket配置        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;# 客户端的ip        proxy_set_header   X-Forwarded-Proto $scheme;# 判断客户端使用的是http还是https        proxy_read_timeout 600s;# 超时设置,表明连接成功以后等待服务器响应的时候,如果不配置默认为90s      }	  # root和alias区别:https://blog.csdn.net/tuoni123/article/details/79712246	  # 真实路径=alias别名指定的路径; 真实路径=root的路径加上location路径	  #      #location /s{      #  alias /opt/vue/dist;      #  index  index.html;      #  try_files $uri $uri/ /s/index.html;      #}    }}

ps: , ws://127.0.0.1:8080/sdmp/webSocket/device/12

6、配置开机启动

# 创建nginx.service 脚本vi /lib/systemd/system/nginx.service# nginx.service内容如下:
[Unit]Description=nginxAfter=network.target [Service]Type=forkingExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/local/nginx/sbin/nginx -s reloadExecStop=/usr/local/nginx/sbin/nginx -s quitPrivateTmp=true [Install]WantedBy=multi-user.target
# 设置开机启动systemctl enable nginx.service# 取消开机启动systemctl disable nginx.service# 查看状态systemctl status nginx.service# 启动服务systemctl start nginx.service# 关闭服务systemctl stop nginx.service# 重启服务systemctl restart nginx.service

7、nginx-readme

# =============nginx readme========================# 安装位置      /usr/local/nginx# 配置文件路径    /usr/local/nginx/conf/nginx.conf# 启动            /usr/local/nginx/sbin/nginx# 重启            /usr/local/nginx/sbin/nginx -s reload# 停止            /usr/local/nginx/sbin/nginx -s stop# 测试配置文件    /usr/local/nginx/sbin/nginx –t# 强制关闭      pkill nginx​# 检查是否启动成功# 打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。# 如果运行的时候不带-c参数,那就采用默认的配置文件,即/usr/local/nginx/conf/nginx.conf# 查看运行进程状态:ps aux | grep nginx# shell脚本# 设置开机启动:systemctl enable nginx.service# 取消开机启动:systemctl disable nginx.service# 查看状态:systemctl status nginx.service# 启动:systemctl start nginx.service# 关闭:systemctl stop nginx.service# 重启:systemctl restart nginx.service

 

你可能感兴趣的文章
linux下编译调试x264
查看>>
debug和release版本的区别
查看>>
x86 指令集发展历程
查看>>
逐行Porgressive隔行Interlaced扫描的超详细讲解
查看>>
使用FFmpeg实现抠图合并功能(chroma key)
查看>>
长宽比 (视频)
查看>>
Pan & Scan和Letterbox
查看>>
资深影迷不可不知的宽高比:Aspect Ratio 电影画面比例
查看>>
MacBook Pro 外接显示器设置竖屏
查看>>
X264的参考帧设置
查看>>
三种帧的说明
查看>>
感知视频编码
查看>>
深度学习 vs 机器学习 vs 模式识别
查看>>
Tone mapping进化论
查看>>
XAVC
查看>>
详解HDR的三个标准——HLG/HDR10/Dolby Vision
查看>>
流言终结者 1080P全高清都等于高画质?
查看>>
PSNR指标值
查看>>
灰度图像-图像增强 中值滤波
查看>>
两种HDR格式(HLG, HDR10)的理解
查看>>