网站首页 > 技术教程 正文
前言
今天给各位介绍下Tengine/Nginx服务器绑定多个域名多个网站的配置方法。
Tengine/Nginx配置文件
- Tengine/Nginx配置文件在默认安装目录下的conf文件夹下,你也可以在终端下使用“whereis nginx”查找它的安装目录。
- 查找nginx安装目录 如下我的nginx配置文件路径即为: /usr/local/nginx/conf/nginx.conf
[root@localhost ~]# whereis nginx nginx: /usr/local/nginx [root@localhost ~]#
Nginx的配置文件
vim /usr/local/nginx/conf/nginx.conf #打开nginx配置文件命令 你也可以使用你喜欢的编辑工具如vi emacs gedit
原文件
#以下为Nginx 配置文件nginx.conf默认内容,已加注解。
user www www-data; #以www会员和www-data会员组运行nginx
worker_processes 1; #最大进程数,一般设为cpu核心数量 如你是4核cpu 可以设为4
#error_log logs/error.log; #指定错误日志文件路径,默认当前配置文件的父级目录logs下的error.log
#error_log logs/error.log notice; #指定错误日志文件路径并指定为只记录notice级别错误
#error_log logs/error.log info; #指定错误日志文件路径并指定为只记录info级别错误
#pid logs/nginx.pid; ##记录nginx运行时的进程ID
events {
worker_connections 1024; #允许的最大连接数即tcp连接数
}
# load modules compiled as Dynamic Shared Object (DSO)
# 动态模块加载(DSO)支持。加入一个模块不再需要重新编译整个Tengine 这个是Tengine特有的
#dso {
# load ngx_http_fastcgi_module.so; #fastcgi模块
# load ngx_http_rewrite_module.so; #URL重写模块
#}
http {
include mime.types; #设定mime类型,类型由conf目录下mime.type文件定义
default_type application/octet-stream; #默认为 任意的二进制数据
## 可配置日志格式: $remote_addr访客ip
## $remote_user已经经过Auth Basic Module验证的用户名
## $time_local访问时间
## $request请求的url
## $body_bytes_sent 传送页面的字节数 $http_referer访问来源
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main; #访问记录日志
sendfile on; #开启高效文件传输模式 注意:如果图片显示不正常把这个改成off。
#tcp_nopush on; #防止网络阻塞
#keepalive_timeout 0;
keepalive_timeout 65; #长连接超时时间,单位是秒
#gzip on; #开启gzip压缩
server {#虚拟主机的配置
listen 80; #监听80端口
server_name localhost; #绑定域名可以有多个,用空格隔开
#charset koi8-r; #字符编码 可设为 utf-8
#access_log logs/host.access.log main; #访问记录日志
location / { ##网站根目录设置在这里
root html; #配置文件父级html目录,可以设到其它目录如/home/www目录,注意目录的所有者和权限 本文开头处user的信息
index index.html index.htm; #默认索引文件,从左到右,如:index.php index.html index.htm 空格分开
}
#error_page 404 /404.html; #指定404错误文件位置 root指定目录下的404.html 以下50x文件同理
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; ##服务器50x得的错误都跳转到html/50x.html文件
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
# 配置处理php文件,需要安装PHP
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all; ##禁止使用.htaccess文件
#}
}
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
修改后
###以下为修改过的nginx.conf配置文件,已加注解。
user www www-data; #以www会员和www-data会员组运行nginx
worker_processes 1; #最大进程数,一般设为cpu核心数量 如你是4核cpu 可以设为4
error_log logs/error.log; #指定错误日志文件路径,默认当前配置文件的父级目录logs下的error.log
#error_log logs/error.log notice; #指定错误日志文件路径并指定为只记录notice级别错误
#error_log logs/error.log info; #指定错误日志文件路径并指定为只记录info级别错误
pid logs/nginx.pid; ##记录nginx运行时的进程ID
events {
use epoll; #新加 提高nginx的性能,限Linux下使用
worker_connections 1024; #允许的最大连接数即tcp连接数
}
# load modules compiled as Dynamic Shared Object (DSO)
# 动态模块加载(DSO)支持。加入一个模块不再需要重新编译整个Tengine 这个是Tengine特有的
#dso {
# load ngx_http_fastcgi_module.so; #fastcgi模块
# load ngx_http_rewrite_module.so; #URL重写模块
#}
http {
include mime.types; #设定mime类型,类型由conf目录下mime.type文件定义
default_type application/octet-stream; #默认为 任意的二进制数据
##可配置日志格式: $remote_addr访客ip
## $remote_user已经经过Auth Basic Module验证的用户名
## $time_local访问时间
## $request请求的url
## $body_bytes_sent 传送页面的字节数
## $http_referer访问来源
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main; #访问记录日志
sendfile on; #开启高效文件传输模式 注意:如果图片显示不正常把这个改成off。
#tcp_nopush on; #防止网络阻塞
#keepalive_timeout 0;
keepalive_timeout 65; #长连接超时时间,单位是秒
gzip on; #开启gzip压缩
## 新加 include 项引入/usr/local/nginx/vhosts/目录下所有.conf结尾的虚拟机配置文件
include /usr/local/nginx/vhosts/*.conf
}
建立虚拟机配置目录
- 在nginx安装目录中新建目录虚拟机配置目录:vhosts
mkdir /usr/local/nginx/vhosts/
新建网站配置文件
vim /usr/local/nginx/vhosts/test.conf
##www.test.my 的配置文件
server { #虚拟主机的配置
listen 80; #监听80端口
server_name www.test.my www.test.my; #绑定域名可以有多个,用空格隔开
#charset koi8-r; #字符编码 可设为 utf-8
charset utf-8;
#access_log logs/host.access.log main; #访问记录日志
location / { ##网站根目录设置在这里
root html; #配置文件父级html目录,可以设到其它目录如/home/www目录,注意目录的所有者和权限 本文开头处user的信息
index index.html index.htm; #默认索引文件,从左到右,如:index.php index.html index.htm 空格分开
}
#error_page 404 /404.html; #指定404错误文件位置 root指定目录下的404.html 以下50x文件同理
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; ##服务器50x得的错误都跳转到html/50x.html文件
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
# 配置处理php文件,需要安装PHP
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all; ##禁止使用.htaccess文件
#}
}
配置多个网站
- 同理,在vhosts目录下生成多个站点的配置文件即可完成多站点多域名共享一台主机。
#如再配置一个域名为 yuntheme.com站点的配置文件
vim /usr/local/nginx/vhosts/yuntheme.conf
#复制刚才的test.conf的内容,只要像下面修改就行了
location / { ##网站根目录设置在这里
root /usr/local/nginx/html/yuntheme; #修改此处
index index.html index.htm;
}
完成配置,重启Nginx
/usr/local/nginx/sbin/nginx -s reload
猜你喜欢
- 2024-09-19 Tomcat获取Nginx反向代理的客户端域名
- 2024-09-19 详解Nginx 运维之域名验证的方法示例
- 2024-09-19 在centos7 创建基于域名的虚拟主机nginx服务器
- 2024-09-19 在 Go 代码中如何绑定 Host?(git绑定github)
- 2024-09-19 记录使用Nginx完成一个域名根据User-Agent适配PC和手机
- 2024-09-19 nginx反向代理禁止ip访问及泛解析访问限制(禁止非法域名解析)
- 2024-09-19 Nginx 反向代理任意请求的域名(nginx反向代理域名访问)
- 2024-09-19 高性能Nginx服务器-DNS域名解析概述
- 2024-09-19 搭建gitlab自定义域名(gitlab局域网搭建)
- 2024-09-19 【Docker入门】Nginx反向代理做前端,多个Docker容器共存做后端
欢迎 你 发表评论:
- 12-16无线密码破解用什么软件(无线密码破解软件哪个好)
- 12-16360路由器设置登录(360路由器登陆口)
- 12-16安全平台教育平台登录(安全平台教育登录账号入口)
- 12-16win7装机版系统(win7系统装机教程)
- 12-151500元以内最强笔记本(懂行的人建议买华为还是联想)
- 12-15电脑很卡怎么办快速解决方法
- 12-15tmp文件是什么文件(tmp文件有什么用)
- 12-15win10教育版如何激活(windows10教育版激活密钥怎么激活)
- 最近发表
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)

本文暂时没有评论,来添加一个吧(●'◡'●)