Nginx

1. 先检查依赖库是否安装

rpm  -qa | grep openssl
rpm  -qa  | grep  zlib
rpm  -qa  | grep pcre

2. 准备文件

文件名:nginx
下载链接:https://pan.baidu.com/s/1dkBq14s5qjKGyo37JVOQ6A
密码:1234

3 安装依赖库

安装openssl
注:一行一命令,勿要拆分了

mkdir /apps/openssl
tar -zxvf  openssl-1.1.1-pre8.tar.gz -C /apps/openssl
cd ./openssl-1.1.1-pre8
./config  shared zlib --prefix=/apps/openssl/  && make && make  install
./config  -t 
make  depend
cd /apps/
ln -s openssl  ssl
vi  /etc/ld.so.conf 
	/apps/openssl/lib   #加入这行代码
ldconfig
vi /etc/profile
    export OPENSSL=/apps/openssl/bin
    export PATH=$OPENSSL:$PATH:$HOME/bin
source  /etc/profile   #加进环境变量

安装pcre

tar -zxvf pcre-8.39.tar.gz  -C /usr # 解压
cd /usr/pcre-8.39		#进入目录
./configure && sudo make && sudo make install #配置编译安装

安装zlib

 tar -zxvf zlib-1.2.11.tar.gz -C /apps#解压
cd /apps/zlib-1.2.11			   #进入目录
./configure && sudo make && sudo make install #配置编译安装

4. 安装Nginx

tar -zxvf nginx-1.21.5.tar.gz -C /apps
cd /apps/nginx-1.21.5			#进入目录
./configure && sudo make && sudo make install #配置编译安装
/usr/local/nginx/sbin/nginx	#启动nginx

5. 修改Nginx配置文件

vi /usr/local/nginx/conf/nginx.conf #编写配置文件
添加内容:
	server {
	    listen       3000; 需要挂载的前端应用的端口号
	    server_name  127.0.0.1;
	
	    #后台服务配置,配置了这个location便可以通过http://域名/jeecg-boot/xxxx 访问        
	    location ^~ /jeecg-boot {
	        proxy_pass              http://127.0.0.1:8080/jeecg-boot/;
	        proxy_set_header        Host 127.0.0.1;
	        proxy_set_header        X-Real-IP $remote_addr;
	        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
	    }
	    #解决Router(mode: 'history')模式下,刷新路由地址不能找到页面的问题
	    location / {
	        root   html;
	        index  index.html index.htm;
	        if (!-e $request_filename) {
	            rewrite ^(.*)$ /index.html?s=$1 last;
	            break;
	        }
	    }
	}
/usr/local/nginx/sbin/nginx -t #检查配置文件是否正确

 # 正确提示如下:
 #  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
 #  nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful	 
 
 /usr/local/nginx/sbin/nginx -s reload #重启nginx

5. Nginx开机自启动

自启方式A: 使用systemctl来管理Nginx的自启(推荐)

a. 创建脚本 /usr/lib/systemd/system/nginx.service

内容如下:

	[Unit]
	Description=The NGINX HTTP and reverse proxy server
	After=syslog.target network.target remote-fs.target nss-lookup.target	
	[Service]
	Type=forking
	PIDFile=/usr/local/nginx/logs/nginx.pid
	ExecStartPre=/usr/local/nginx/sbin/nginx -t
	ExecStart=/usr/local/nginx/sbin/nginx
	ExecReload=/usr/local/nginx/sbin/nginx -s reload
	ExecStop=/usr/local/nginx/sbin/nginx -s quit
	PrivateTmp=true	
	[Install]
	WantedBy=multi-user.target

脚本参数介绍参见文档linux service脚本

b. 刷新配置
$ systemctl daemon-reload
c.设置开机使用
$ systemctl enable nginx.service

自启方式B:使用service来管理服务

vim  /etc/init.d/boot.local 
	/usr/local/nginx/sbin/nginx  # 开头添加这一句话 	

博主在这个文件里还添加了redis的自启命令,当这行语句位于redis语句之后时,就会失效,所以最好把这行语句放到所有正式语句的前面
重启后查看:

ps -ef |grep nginx

在这里插入图片描述

6. Nginx常用命令

/usr/local/nginx/sbin/nginx -h	#命令帮助
/usr/local/nginx/sbin/nginx  #启动nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf  #配置文件方式启动
/usr/local/nginx/sbin/nginx -s stop (quit)  #停止nginx
/usr/local/nginx/sbin/nginx -s reload  #重启nginx
/usr/local/nginx/sbin/nginx -t  #验证配置文件(检测是否安装成功)
ps -ef | grep nginx  #查看nginx进程
netstat -tunlp  #查看端口占用
netstat -tunlp |grep  #查看指定端口
kill -QUIT Nginx主进程号  #停止进程
kill -TERM Nginx主进程号  #快速停止
kill -9 nginx  #强制停止
kill -HUP Nginx主进程号  #平滑重启

7.其他

SuSE 12 linux 开发环境搭建 之 jdk安装
SuSE 12 linux 开发环境搭建 之 mysql安装
SuSE 12 linux 开发环境搭建 之 nginx安装与自启设置
SuSE 12 linux 开发环境搭建 之 redis安装与自启设置

8. 参考文档

自定义systemctl管理服务(redis)
linux service脚本

Logo

更多推荐