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;}
}