nginx下添加http_ssl_module并且配置域名,指定端口

1.切换到源码包:

cd /home/nginx-1.23.1

2.进行编译:

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

3.配置完成后,运行命令:

make

make命令执行后,不要进行make install,否则会覆盖安装。

4.备份原有已安装好的nginx:

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

5.停止nginx状态:

/usr/local/nginx/sbin/nginx -s stop

6.将编译好的nginx覆盖掉原有的nginx:

cd /home/nginx-1.23.1/

cp ./objs/nginx /usr/local/nginx/sbin/

7.提示是否覆盖,输入yes即可。

8.然后启动nginx:

/usr/local/nginx/sbin/nginx

9.进入nginx/sbin目录下,通过命令查看模块是否已经加入成功:

cd /usr/local/nginx/sbin/

./nginx -V

10.有以下提示,证明已经编译成功:

nginx version: nginx/1.23.1

built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)

built with OpenSSL 1.0.2k-fips 26 Jan 2017

TLS SNI support enabled

configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

nginx配置域名

bash 复制代码
     server {
	    listen 443 ssl;
	    server_name xxx.cn;
	    ssl_certificate     cert/xxx.pem;
	    ssl_certificate_key cert/xxx.key;
	    ssl_session_timeout 5m;
	    ssl_protocols TLSv1.2 TLSv1.3;
	    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
	    ssl_prefer_server_ciphers on;
	    add_header Content-Security-Policy upgrade-insecure-requests;
	    client_max_body_size 200M;
	    server_tokens off;
	    autoindex on;
	    charset uft8;

        error_page 500 502 503 504 /50x.html;

        location / {
            root /mnt/dist;
            index index.html index.htm;
            error_page 405 =200 $request_uri;
            try_files $uri $uri/ /index.html;
        }
        location /api{
                proxy_pass http://127.0.0.1:8080;
                proxy_read_timeout  360;
                proxy_set_header   X-Forwarded-Proto $scheme;
                proxy_set_header   Host              $http_host;
                proxy_set_header   X-Real-IP         $remote_addr;
                client_max_body_size 500m;
        }
        location = /50x.html {
                root /usr/share/nginx/html;
        }
    }

附带linux下防火墙和开放端口

bash 复制代码
#查看防火墙是否开启(如果显示running,则防火墙为开启状态):
firewall-cmd --state

#关闭防火墙:
systemctl stop firewalld.service

#开启防火墙
systemctl start firewalld.service
1、开启防火墙 
     systemctl start firewalld
 ​
 2、开放指定端口
       firewall-cmd --zone=public --add-port=443/tcp --permanent
       
  		命令含义:
 		--zone #作用域
 		--add-port=1935/tcp  #添加端口,格式为:端口/通讯协议
 		--permanent  #永久生效,没有此参数重启后失效
​
 3、重启防火墙
       firewall-cmd --reload
# 查询端口是否开放
firewall-cmd --query-port=8080/tcp
lsof -i:8080(如果没有lsof,可以使用  yum install lsof  下载)


# 开放80端口
firewall-cmd --permanent --add-port=80/tcp
 
 
# 移除端口
firewall-cmd --permanent --remove-port=8080/tcp
 
 
#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload
相关推荐
隆里卡那唔4 小时前
在dify中通过http请求neo4j时为什么需要将localhost变为host.docker.internal
http·docker·neo4j
charlee444 小时前
nginx部署发布Vite项目
nginx·性能优化·https·部署·vite
~山有木兮5 小时前
LiteHub中间件之限流实现
网络·http·中间件
游戏开发爱好者87 小时前
iOS App首次启动请求异常调试:一次冷启动链路抓包与初始化流程修复
websocket·网络协议·tcp/ip·http·网络安全·https·udp
2501_915106327 小时前
频繁迭代下完成iOS App应用上架App Store:一次快速交付项目的完整回顾
websocket·网络协议·tcp/ip·http·网络安全·https·udp
CRMEB定制开发7 小时前
【实战】CRMEB Pro 企业版安装教程(附 Nginx 反向代理配置 + 常见问题解决)
nginx·商城系统·微信商城·crmeb
00后程序员张13 小时前
免Mac上架实战:全平台iOS App上架流程的工具协作经验
websocket·网络协议·tcp/ip·http·网络安全·https·udp
笑衬人心。15 小时前
HTTPS详解:原理 + 加解密过程 + 面试问答
java·网络协议·http·面试·https
bing_15815 小时前
MQTT 和 HTTP 有什么本质区别?
网络·网络协议·http
代码讲故事16 小时前
多种方法实现golang中实现对http的响应内容生成图片
开发语言·chrome·http·golang·图片·快照·截图