当前位置: 首页 > news >正文

nginx安装教程

需求背景

最近发现在Centos7.9上使用sudo yum install nginx这个命令安装的nginx配置好server后,静态资源都可以访问,但是访问的后台接口一直无法访问,提示502,不知道是项目配置的问题还是其它问题,安装了3遍都是一样的。其中配置文件在另一台机器上完美运行。所以得出的结论是不要使用这个命令来安装nginx,虽然简单,但是各种毛病。于是写一个手动安装的教程。

删除卸载

find /  -name  nginx
# 把出现的文件夹都删除
rm -rf /usr/local/nginx
rm -rf /usr/local/nginx/sbin/nginx
rm -rf /opt/nginx-1.20.1/objs/nginx# 移除组件
sudo yum remove nginx

安装编译

# 进入到需要下载的文件夹中
cd /opt
wget http://nginx.org/download/nginx-1.20.1.tar.gz
# 解压
tar -zxvf nginx-1.20.1.tar.gz
# 安装模块
yum -y install gcc-c++ pcre-devel openssl-devel zlib-devel# 进入到文件夹
cd nginx-1.20.1
# 配置
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-stream --with-stream_ssl_module --with-file-aio --with-http_realip_module# 执行命令若出现./configure c compiler cc is not found,执行命令yum -y install gcc gcc-c++ autoconf automake make
# 注意这个命令,nake install会把nginx以前安装的完全替换掉,需要小心
make && make install# 然后去修改nginx.conf,安装目录=/usr/local/nginx

nginx.conf

#user  nobody;
worker_processes  1;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;# 文件大小限制,默认1mclient_max_body_size     50m;client_header_timeout    1m;client_body_timeout      1m;proxy_connect_timeout    60s;proxy_read_timeout      1m;proxy_send_timeout      1m;# websocket需要增加该配置map $http_upgrade $connection_upgrade {default keep-alive;'websocket' upgrade;}#gzip  on;upstream websocket_name{server 192.168.199.200:11118;}upstream iot_server_name{server 192.168.199.201:18080;}server {#监听443端口listen 443 ssl;#你的域名server_name cloud.test.com;#ssl证书的pem文件路径ssl_certificate  /usr/local/nginx/conf/cert/aiot.test.com.pem;#ssl证书的key文件路径ssl_certificate_key /usr/local/nginx/conf/cert/aiot.test.com.key;location /iot/ {# enterprise wechat testadd_header X-Content-Type-Options nosniff;proxy_set_header X-scheme $scheme;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;# 注意必须设置 Host,否则使用 Java Client 无法正常访问 MinIOproxy_set_header Host $http_host;proxy_set_header X-Nginx-Proxy true;proxy_hide_header X-Powered-By;proxy_hide_header Vary;client_max_body_size 2048m; proxy_pass http://iot_server_name;# 重复提交情况proxy_next_upstream off;proxy_read_timeout 600;proxy_send_timeout 600;proxy_connect_timeout 600;}location ^~/aiot {alias /usr/local/nginx/html/aiot;try_files $uri $uri/ /index.html;index index.html;}location / {index index.html index.htm;root /usr/local/nginx/html/aiot;# 下面这句话可以解决vue打包部署后,页面刷新报404的问题try_files $uri $uri/ /index.html;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}error_page 404 /index.html;location = /index.html {root /usr/local/nginx/html/aiot;}}server {listen 80;server_name cloud.test.com;location /iot/ {add_header X-Content-Type-Options nosniff;proxy_set_header X-scheme $scheme;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;# 注意必须设置 Host,否则使用 Java Client 无法正常访问 MinIOproxy_set_header Host $http_host;proxy_set_header X-Nginx-Proxy true;proxy_hide_header X-Powered-By;proxy_hide_header Vary;client_max_body_size 2048m; proxy_pass http://iot_server_name;# 重复提交情况proxy_next_upstream off;proxy_read_timeout 600;proxy_send_timeout 600;proxy_connect_timeout 600;}# location /user/ {#     proxy_pass http://172.168.1.1:8181/user/;# }# 重点在这里,websocket后面没有斜杠,和其它项目的区别location /websocket {proxy_pass http://websocket_name;proxy_read_timeout 300s;proxy_send_timeout 300s;proxy_redirect off;proxy_set_header Host $host:5052;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;#升级http1.1到 websocket协议proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection  $connection_upgrade;}location ^~/aiot {alias /usr/local/nginx/html/aiot;try_files $uri $uri/ /index.html;index index.html;}location / {index index.html index.htm;root /usr/local/nginx/html/aiot;# 下面这句话可以解决vue打包部署后,页面刷新报404的问题try_files $uri $uri/ /index.html;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}error_page 404 /index.html;location = /index.html {root /usr/local/nginx/html/aiot;}}server {listen       80;# 自己需要监听的域名server_name cloud.test.com;#将请求转成httpsrewrite ^(.*)$ https://$host$1 permanent;}}

nginx-cmd.sh

# 启动命令
#!/bin/bash
# Nginx可执行文件路径 别忘了换成你自己安装的路径
# nginx-cmd.sh
NGINX_PATH="/usr/local/nginx/sbin/nginx"start() {echo "Starting Nginx..."$NGINX_PATH
}stop() {echo "Stopping Nginx..."$NGINX_PATH -s stop
}restart() {echo "Restarting Nginx..."$NGINX_PATH -s reload
}case "$1" instart)start;;stop)stop;;restart)restart;;*)echo "Usage: $0 {start|stop|restart}"exit 1;;
esacexit 0

启动命令

# 给执行的权限
chmod -R 777 /usr/local/nginx/nginx-cmd.sh# 然后执行-启动
nginx-cmd start# 然后执行-停止
nginx-cmd stop# 然后执行-重启,如果nginx没有启动过,执行restart命令会报错,请直接执行start命令
nginx-cmd restart

结束

-----华丽的分割线,以下是凑字数,大家不用花时间看,快去改代码-----

-----华丽的分割线,以下是凑字数,大家不用花时间看,快去改代码-----

-----华丽的分割线,以下是凑字数,大家不用花时间看,快去改代码-----

package cn.renkai721.bean.vo;import lombok.extern.slf4j.Slf4j;@Slf4j
public class MakeUpTheWordCount {private String make_up_the_word_count_column_999999999_1;private String make_up_the_word_count_column_999999999_2;private String make_up_the_word_count_column_999999999_3;private String make_up_the_word_count_column_999999999_4;private String make_up_the_word_count_column_999999999_5;private String make_up_the_word_count_column_999999999_6;private String make_up_the_word_count_column_999999999_7;private String make_up_the_word_count_column_999999999_8;private String make_up_the_word_count_column_999999999_9;private String make_up_the_word_count_column_999999999_10;private String make_up_the_word_count_column_999999999_11;private String make_up_the_word_count_column_999999999_12;private String make_up_the_word_count_column_999999999_13;private String make_up_the_word_count_column_999999999_14;private String make_up_the_word_count_column_999999999_15;private String make_up_the_word_count_column_999999999_16;private String make_up_the_word_count_column_999999999_17;private String make_up_the_word_count_column_999999999_18;private String make_up_the_word_count_column_999999999_19;private String make_up_the_word_count_column_999999999_20;public String getMake_up_the_word_count_column_999999999_1() {return make_up_the_word_count_column_999999999_1;}public void setMake_up_the_word_count_column_999999999_1(String make_up_the_word_count_column_999999999_1) {this.make_up_the_word_count_column_999999999_1 = make_up_the_word_count_column_999999999_1;}public String getMake_up_the_word_count_column_999999999_2() {return make_up_the_word_count_column_999999999_2;}public void setMake_up_the_word_count_column_999999999_2(String make_up_the_word_count_column_999999999_2) {this.make_up_the_word_count_column_999999999_2 = make_up_the_word_count_column_999999999_2;}public String getMake_up_the_word_count_column_999999999_3() {return make_up_the_word_count_column_999999999_3;}public void setMake_up_the_word_count_column_999999999_3(String make_up_the_word_count_column_999999999_3) {this.make_up_the_word_count_column_999999999_3 = make_up_the_word_count_column_999999999_3;}public String getMake_up_the_word_count_column_999999999_4() {return make_up_the_word_count_column_999999999_4;}public void setMake_up_the_word_count_column_999999999_4(String make_up_the_word_count_column_999999999_4) {this.make_up_the_word_count_column_999999999_4 = make_up_the_word_count_column_999999999_4;}public String getMake_up_the_word_count_column_999999999_5() {return make_up_the_word_count_column_999999999_5;}public void setMake_up_the_word_count_column_999999999_5(String make_up_the_word_count_column_999999999_5) {this.make_up_the_word_count_column_999999999_5 = make_up_the_word_count_column_999999999_5;}public String getMake_up_the_word_count_column_999999999_6() {return make_up_the_word_count_column_999999999_6;}public void setMake_up_the_word_count_column_999999999_6(String make_up_the_word_count_column_999999999_6) {this.make_up_the_word_count_column_999999999_6 = make_up_the_word_count_column_999999999_6;}public String getMake_up_the_word_count_column_999999999_7() {return make_up_the_word_count_column_999999999_7;}public void setMake_up_the_word_count_column_999999999_7(String make_up_the_word_count_column_999999999_7) {this.make_up_the_word_count_column_999999999_7 = make_up_the_word_count_column_999999999_7;}public String getMake_up_the_word_count_column_999999999_8() {return make_up_the_word_count_column_999999999_8;}public void setMake_up_the_word_count_column_999999999_8(String make_up_the_word_count_column_999999999_8) {this.make_up_the_word_count_column_999999999_8 = make_up_the_word_count_column_999999999_8;}public String getMake_up_the_word_count_column_999999999_9() {return make_up_the_word_count_column_999999999_9;}public void setMake_up_the_word_count_column_999999999_9(String make_up_the_word_count_column_999999999_9) {this.make_up_the_word_count_column_999999999_9 = make_up_the_word_count_column_999999999_9;}public String getMake_up_the_word_count_column_999999999_10() {return make_up_the_word_count_column_999999999_10;}public void setMake_up_the_word_count_column_999999999_10(String make_up_the_word_count_column_999999999_10) {this.make_up_the_word_count_column_999999999_10 = make_up_the_word_count_column_999999999_10;}public String getMake_up_the_word_count_column_999999999_11() {return make_up_the_word_count_column_999999999_11;}public void setMake_up_the_word_count_column_999999999_11(String make_up_the_word_count_column_999999999_11) {this.make_up_the_word_count_column_999999999_11 = make_up_the_word_count_column_999999999_11;}public String getMake_up_the_word_count_column_999999999_12() {return make_up_the_word_count_column_999999999_12;}public void setMake_up_the_word_count_column_999999999_12(String make_up_the_word_count_column_999999999_12) {this.make_up_the_word_count_column_999999999_12 = make_up_the_word_count_column_999999999_12;}public String getMake_up_the_word_count_column_999999999_13() {return make_up_the_word_count_column_999999999_13;}public void setMake_up_the_word_count_column_999999999_13(String make_up_the_word_count_column_999999999_13) {this.make_up_the_word_count_column_999999999_13 = make_up_the_word_count_column_999999999_13;}public String getMake_up_the_word_count_column_999999999_14() {return make_up_the_word_count_column_999999999_14;}public void setMake_up_the_word_count_column_999999999_14(String make_up_the_word_count_column_999999999_14) {this.make_up_the_word_count_column_999999999_14 = make_up_the_word_count_column_999999999_14;}public String getMake_up_the_word_count_column_999999999_15() {return make_up_the_word_count_column_999999999_15;}public void setMake_up_the_word_count_column_999999999_15(String make_up_the_word_count_column_999999999_15) {this.make_up_the_word_count_column_999999999_15 = make_up_the_word_count_column_999999999_15;}public String getMake_up_the_word_count_column_999999999_16() {return make_up_the_word_count_column_999999999_16;}public void setMake_up_the_word_count_column_999999999_16(String make_up_the_word_count_column_999999999_16) {this.make_up_the_word_count_column_999999999_16 = make_up_the_word_count_column_999999999_16;}public String getMake_up_the_word_count_column_999999999_17() {return make_up_the_word_count_column_999999999_17;}public void setMake_up_the_word_count_column_999999999_17(String make_up_the_word_count_column_999999999_17) {this.make_up_the_word_count_column_999999999_17 = make_up_the_word_count_column_999999999_17;}public String getMake_up_the_word_count_column_999999999_18() {return make_up_the_word_count_column_999999999_18;}public void setMake_up_the_word_count_column_999999999_18(String make_up_the_word_count_column_999999999_18) {this.make_up_the_word_count_column_999999999_18 = make_up_the_word_count_column_999999999_18;}public String getMake_up_the_word_count_column_999999999_19() {return make_up_the_word_count_column_999999999_19;}public void setMake_up_the_word_count_column_999999999_19(String make_up_the_word_count_column_999999999_19) {this.make_up_the_word_count_column_999999999_19 = make_up_the_word_count_column_999999999_19;}public String getMake_up_the_word_count_column_999999999_20() {return make_up_the_word_count_column_999999999_20;}public void setMake_up_the_word_count_column_999999999_20(String make_up_the_word_count_column_999999999_20) {this.make_up_the_word_count_column_999999999_20 = make_up_the_word_count_column_999999999_20;}
}

相关文章:

  • Python 学习 第四册 第8章 结构化的文本文件
  • 【LeetCode热题 100】三数之和
  • Python日志管理利器:如何高效管理平台日志
  • 【机器学习】智能创意工厂:机器学习驱动的AIGC,打造未来内容新生态
  • CentOS中的rename命令
  • 别让日志拖垮网站速度
  • Python多语言欧拉法和预测校正器实现
  • 20240621每日后端---------如何优化项目中的10000个if-else 语句?
  • ⭐Unity 控制任意UI的渐隐渐显
  • JDBC从入门到精通-笔记(一):JDBC基本概念与开发基础
  • 构建安全高效的前端权限控制系统
  • Flutter 实现软鼠标
  • 寻找重复数 - LeetCode 热题 100
  • QCombox绑定QMap
  • Map-JAVA面试常问
  • CentOS7 安装JDK
  • classpath对获取配置文件的影响
  • ES6 学习笔记(一)let,const和解构赋值
  • Github访问慢解决办法
  • iOS动画编程-View动画[ 1 ] 基础View动画
  • JavaScript对象详解
  • JSDuck 与 AngularJS 融合技巧
  • Linux CTF 逆向入门
  • Python socket服务器端、客户端传送信息
  • python学习笔记 - ThreadLocal
  • quasar-framework cnodejs社区
  • sessionStorage和localStorage
  • vue:响应原理
  • 百度小程序遇到的问题
  • 从零搭建Koa2 Server
  • 从零开始的无人驾驶 1
  • 大数据与云计算学习:数据分析(二)
  • 基于Vue2全家桶的移动端AppDEMO实现
  • 前端性能优化——回流与重绘
  • 试着探索高并发下的系统架构面貌
  • 思考 CSS 架构
  • 为什么要用IPython/Jupyter?
  • 应用生命周期终极 DevOps 工具包
  • 在Unity中实现一个简单的消息管理器
  • 智能合约Solidity教程-事件和日志(一)
  • ionic异常记录
  • raise 与 raise ... from 的区别
  • Semaphore
  • 交换综合实验一
  • 数据库巡检项
  • ​第20课 在Android Native开发中加入新的C++类
  • ​学习一下,什么是预包装食品?​
  • ‌[AI问答] Auto-sklearn‌ 与 scikit-learn 区别
  • #DBA杂记1
  • #我与Java虚拟机的故事#连载19:等我技术变强了,我会去看你的 ​
  • (2)从源码角度聊聊Jetpack Navigator的工作流程
  • (4)事件处理——(6)给.ready()回调函数传递一个参数(Passing an argument to the .ready() callback)...
  • (aiohttp-asyncio-FFmpeg-Docker-SRS)实现异步摄像头转码服务器
  • (windows2012共享文件夹和防火墙设置
  • (八)Docker网络跨主机通讯vxlan和vlan