nginx web服务器

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;
        }

    }      

}

 

posted @ 2019-08-06 21:03  myfu  阅读(194)  评论(0编辑  收藏  举报