nginx二级域名配置[CentOS]
2024-09-28 05:23:36
背景
只有一台云服务器,部署了自己写的后端管理系统,又需要部署下自己的个人博客平台,但是只有一个域名,想要合理的利用下二级域名。
域名配置
首先需要配置域名解析,讲需要添加的二级域名添加到现有的解析记录里:
- 各个平台操作类似,我的域名在西部数据买的,直接配置就好,截图显示如下:
- 服务器上配置安全策略打开对应端口:
服务器配置
- 阿里云安全组策略配置:
2.服务器安装nginx,已安装略过
Nginx配置
- nginx现有配置:
在conf下新增 hosts文件夹。【可自定义】
#user nobody;
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info; events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on; server {
listen 80;
server_name mount.pub;
rewrite ^(.*)$ https://${server_name}$1 permanent; error_page 500 502 503 504 /50x.html;
root /var/blog/dist/;
}
server {
listen 443 ssl;
server_name mount.pub;
ssl on;
# https证书
ssl_certificate /usr/local/nginx/conf/cert/1_www.xxx.pub_bundle.crt;
ssl_certificate_key /usr/local/nginx/conf/cert/2_www.xxx.pub.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on; location / {
root /var/blog/dist;
index index.html index.htm;
# 避免中文乱码
charset utf-8,gbk;
}
location /app/ {
proxy_pass https://127.0.0.1:8081;
client_max_body_size 16m;
client_body_buffer_size 128k;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
#跨域访问设置
add_header Access-Control-Allow-Origin *;
}
}
#二级域名 配置文件夹
include hosts/*.conf;
}
- 在hosts下新增二级域名的配置文件
例如我需要加的:admin.mount.pub.conf
配置如下:
server {
default_type 'text/html';
charset utf-8;
listen 80;
autoindex off;
server_name admin.mount.pub;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return 404;
}
location / {
index index.html index.htm;
add_header Access-Control-Allow-Origin *;
#二级域名对应的文件路径
root /var/www/dist/;
}
}`
- nginx配置生效
reload配置
# /usr/local/nginx/ 是我的nginx安装路径
/usr/local/nginx/sbin/nginx -s reload
页面访问生效
效果如下
最新文章
- Java(一)
- C#获取本机公网IP
- .NET下Excel报表的打印
- socket 简介
- 设置 Eclipse 智能代码提示,大幅度减少 alt+/ 使用频率,打每个字都出现代码提示的办法
- hql查询技巧
- 台式电脑部署xen虚拟化的各种问题
- SQL Server 死锁检查
- 【多重背包模板】poj 1014
- iOS11、iPhone X、Xcode9 适配
- 无法连接MySQL
- Git版本控制 — 日常使用(二)
- 2017-9-11-Linux开机启动脚本
- 实验隐藏参数";_allow_resetlogs_corruption";的使用
- [datatable]排序时指定某列不可排序
- Redis----windows下的常用命令二
- sql server merge into 与update 批量更新1 百万测试数据的性能比较
- Spring.Net 入门学习(一)实现控制器翻转与依赖注入
- Python 调试:step into/step out/step over 的区别
- Ubuntu12.10下Python(cx_Oracle)访问Oracle解决方案