网站首页 > 精选教程 正文
前言
今天给各位介绍下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-29 nginx 短链接专用域名 nginx urlhash
- 2024-09-29 域名备案流程总结 域名备案视频教程
- 2024-09-29 node应用部署到nginx服务器的nginx配置
- 2024-09-29 APP分发平台的域名HTTPS域名怎么绑定
- 2024-09-29 服务器域名如何配置全攻略 服务器域名搭建
- 2024-09-29 详解在nginx中设置三级域名的方法示例
你 发表评论:
欢迎- 最近发表
-
- 我的世界光影MOD下载(我的世界光影mod下载安装)
- 我的世界1.7/1.8VoxelMap小地图MOD下载
- 我的世界1.7.10多世界 整合包(我的世界1.7.10forge整合包)
- 我的世界1.8最好用的修改器下载(我的世界1.8最好用的修改器下载安装)
- 我的世界更多弯曲动作MOD下载(我的世界更多弯曲动作mod下载手机版)
- 我的世界龙珠MOD下载(我的世界龙珠模组整合包下载)
- 我的世界1.7.10以太2 下载(我的世界以太2mod1.12.2)
- 我的世界虚拟人生MOD下载分享(我的世界虚拟人生下载安装)
- 我的世界无正版账号的简单联机方法(非网易版,仅适用于局域网)
- “我的语言极限,即是我的世界的极限。” ——《On Java》书籍推荐
- 标签列表
-
- nginx反向代理 (57)
- nginx日志 (56)
- nginx限制ip访问 (62)
- mac安装nginx (55)
- java和mysql (59)
- java中final (62)
- win10安装java (72)
- java启动参数 (64)
- java链表反转 (64)
- 字符串反转java (72)
- java逻辑运算符 (59)
- java 请求url (65)
- java信号量 (57)
- java定义枚举 (59)
- java字符串压缩 (56)
- java中的反射 (59)
- java 三维数组 (55)
- java插入排序 (68)
- java线程的状态 (62)
- java异步调用 (55)
- java中的异常处理 (62)
- java锁机制 (54)
- java静态内部类 (55)
- java怎么添加图片 (60)
- java 权限框架 (55)
本文暂时没有评论,来添加一个吧(●'◡'●)