您的位置:首页 > 运维架构 > Nginx

nginx的安装及基本配置,及多个域名服务

2016-06-24 16:34 603 查看
centos6.x yum默认没有nginx的软件包

安装方式:

到nginx下载页面http://nginx.org/en/linux_packages.html#stable,复制CENTOS 6的nginx软件源安装包

运行命令:wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

安装rpm包 yum install nginx-release-centos-6-0.el6.ngx.noarch.rpm -y , 此步实际只是加入了nginx的软件包源

执行 yum install nginx -y 就可以安装好nginx了

nginx默认安装为linux的服务

使用service nginx start, stop, restart, try-restart, reload, force-reload, status来操作nginx

nginx的配置文件默认读取/etc/nginx/nginx.conf文件

nginx的配置都是由 directives组成,directives由简单指令或者区块指令组成

简单指令:listen 80;

区块指令由{}包含,区块指令又可以包含多个简单指令和区块指令:

http {
server {
}
}


http可以有多个server,多个server可以监听多个端口在同一服务器为多个应用提供服务。

但如果你同时有多个域名www.you.com,news.you.com, mail.you.com在同一个服务器进行服务,那么www.you.com,mail.you.com:8080, news.you.com:81这样的访问方式显然是不合适显然是不合适的,幸运的是nginx已经提供了通过域名过滤的规则

server
{
listen 80;
server_name www.you.com;
location / {
#....
proxy_pass http://localhost:8880; }
##### other directive
}

server
{
listen 80;
server_name news.you.com;
location / {
#....
proxy_pass http://localhost:8881; }
##### other directive
}

server
{
listen 80;
server_name mail.you.com;
location / {
#....
proxy_pass http://localhost:8882; }
##### other directive
}


最终分别运行各个应用监听对应端口即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx 多域名 server-nam