首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nginx web服务器

nginx web服务器

作者头像
郭耀华
发布2019-10-23 15:10:54
4.8K0
发布2019-10-23 15:10:54
举报
文章被收录于专栏:郭耀华‘s Blog郭耀华‘s Blog

1.安装nginx之前需提前安装pcre pcre-devel 和开发者工具

yum install pcre pcre-devel -y

yum groupinstall "Development Tools"

ps:下载完后需要要检查 rpm -qa pcre pcre-devel

2.下载nginx源代码并解压

tar xf nginx-1.6.3.tar.gz

3.配置

先提前添加用户useradd www -s /sbin/nologin -M

yum install openssl openssl-devel -y

./configure --help 查看帮助

./configure --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --prefix=/application/nginx-1.6.3

echo $?

4.编译安装

make

make install

5.创建软连接

ln -s /application/nginx-1.6.3/ /application/nginx

6.启动nginx

/application/nginx/sbin/nginx

ps:若出现问题

需yum groupinstall 以下包

7.更改配置文件,将server_name 改为自己想更改的域名,同时修改客户端的hosts文件

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  www.fumy.com;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

8.更改index.html文件测试

<html>
<meta charset="utf-8"/>
<head>
<title>老男孩运维学习</title>
</head>
<body background="kobe.jpg">
myfu 最棒!
</body>
</html>

9.在没有主页目录的时候会出现403forbidden,为了防止此类发生,可添加autoindex on;

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  www.fumy.com;
        autoindex on;
        location / {
            root   html/fumy;
            index  index.html index.htm;
        }
       
    }
    server {
        listen       80;
        server_name  www.myfu.com;
        autoindex on;
        location / {
            root   html/myfu;
            index  index.html index.htm;
        }
        
    }       

}

10.分别配置基于域名、端口和ip的虚拟服务器.

一个网卡配置多个子接口

ifconfig ens192:0 10.3.190.116/24 up

ip addr add 10.3.190.117/24 dev ens192 label ens192:1

修改配置后若 /application/nginx/sbin/nginx -s reload不生效

可 /application/nginx/sbin/nginx -s stop后再启动

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen 10.3.190.115:80;
        server_name  www.fumy.com;
        autoindex on;
        location / {
            root   html/fumy;
            index  index.html index.htm;
        }
       
    }
    server {
        listen 10.3.190.116:81;
        server_name  www.myfu.com;
        autoindex on;
        location / {
            root   html/myfu;
            index  index.html index.htm;
        }
        
    } 
    server {
        listen 10.3.190.117:82;
        server_name  www.fmy.com;
        location / {
            root   html/fmy;
            index  index.html index.htm;
        }

    }      

}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-08-06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
SSL 证书
腾讯云 SSL 证书(SSL Certificates)为您提供 SSL 证书的申请、管理、部署等服务,为您提供一站式 HTTPS 解决方案。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档