赞
踩
说明:尝试使用CentOs8.5安装nginx1.9.9失败,make的时候报错了,后面降低版本为CentOs7.5安装成功了,参考文章:【精选】centos7安装nginx-1.9.9_linx centos nginx 1.9.9版本 nginx error log file: "/-CSDN博客
防火墙放行80端口参考:linux防火墙相关命令-CSDN博客
一、安装nginx编译所需环境
- yum install -y gcc-c++ # 编译使用
-
- yum install -y pcre pcre-devel # pcre库
-
- yum install -y zlib zlib-devel # 文件解压缩
-
- yum install -y openssl openssl-devel # 配置https服务需要
二、安装nginx
- mkdir -p /home/local
- cd /home/local
-
- wget http://nginx.org/download/nginx-1.15.9.tar.gz #获取安装包
-
- tar -zxvf nginx-1.15.9.tar.gz #解压安装包
-
- cd nginx-1.15.9/
-
- ./configure --prefix=/usr/local/nginx --with-http_stub_status_module
- --with-http_ssl_module
-
- make
-
- make install
-
- cd /usr/local/nginx/sbin
-
- ./nginx # 启动
-
- systemctl stop firewalld # 关闭防火墙
-
- PATH=$PATH:/usr/local/nginx/sbin
-
- echo "PATH=$PATH:/usr/local/nginx/sbin" >>/root/.bashrc
-
- # 设置开机启动
- echo "/usr/local/nginx/sbin/nginx">>/etc/rc.local
- chmod +x /etc/rc.d/rc.local
-
- netstat -anplut |grep nginx # 查看端口
- ps aux | grep nginx # 查看进程
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
三、浏览器输入http://192.168.6.73访问
四、重启/关闭
- cd /usr/local/nginx/sbin
-
- ./nginx -s reload # 重启nginx
-
- ./nginx -s quit # 关闭nginx
五、卸载nginx
ps aux | grep nginx
- kill 994 # 根据进程ID杀进程
-
- find / -name nginx # 查找nginx相关文件
- rm -rf /usr/local/nginx # 删除编译文件
-
- rm -rf /home/local/nginx-1.15.9 # 删除源文件
-
- # 删除开机启动配置
-
- rm -rf /etc/init.d/nginx
六、配置ssl证书以便https方式访问域名
1、先要购买证书,可选择测试版免费的
2、再创建证书
3.点验证,会提示在域名控制台添加DNS解析记录
4、打开域名解析配置,把上图提供的参数配置解析
5、添加后点第三步验证
6、验证成功后刷新页面,会有已签发记录
7、点下载会展示可下载的服务器证书,这里我们下载nginx的
8、将下载好的文件解压上传到nginx目录下,可重命名文件
- cd /usr/local/nginx/
- mkdir certificate
9.打开nginx.conf更改配置,https需要监听443端口,如果是走的http监听80端口转发到https
- server {
- listen 443 ssl;
- server_name www.xxx.com;
-
- ssl on;
- ssl_certificate /usr/local/nginx/certificate/tool_ssl.pem;
- ssl_certificate_key /usr/local/nginx/certificate/tool_ssl.key;
- ssl_session_timeout 5m;
- ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
- # 服务器支持的TLS版本
- ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
- # 开启由服务器决定采用的密码套件
- ssl_prefer_server_ciphers on;
-
- location / {
- root /home/app/minigame/ui;
- try_files $uri $uri/ /index.html;# 不加刷新会404
- index index.html index.htm;
- }
-
- location ^~/prod-api/ {
- proxy_pass http://127.0.0.1:8080/;
- }
-
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
-
- server {
- listen 80;
- server_name www.xxx.com;
- # 将请求改写为HTTPS(这里写你配置了HTTPS的域名)
- rewrite ^(.*)$ https://www.xxx.com;
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
10、重启nginx,通过https://www.xxx.com可访问成功
- cd /usr/local/nginx/sbin
- ./nginx -s reload
注:若nginx未安装ssl模块解决方式参考文章:Nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf-CSDN博客
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。