python之路_eginx相关

关闭防火墙html

systemctl stop firewalld.service

1、nginx安装linux

一、下载安装包nginx

wget http://nginx.org/download/nginx-1.12.2.tar.gz

二、解压安装包vim

unzip nginx-1.12.2.tar.gz

三、编译安装nginx前的准备浏览器

a、添加 一个虚拟用户:app

  linux每一个进程要有一个对应的用户,以下命令。curl

useradd -s /sbin/nologin -M  www   #www为设置的用户名

b、安装nginx依赖软件包:测试

  nginx依赖pcre-devel 和openssl-devel软件包,命令以下。网站

yum install pcre-devel openssl-devel -y

  以下命令能够查看安装结果。url

rpm -qa pcre-devel openssl-devel

四、编译安装nginx

步骤一:进入上述解压后的安装文件后,执行以下命令:

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

步骤二:

make

步骤三:

make install 

  补充:echo $?命令能够查看上个命令的执行结果,0 表示执行成功,其余表示失败!!!

 2、nginx搭建网站流程

#启动nginx:
/application/nginx-1.12.2/sbin/nginx

  以下为搭建www.etiantian.org网站流程

1.修改nginx.conf文件 

#切换到以下目录:
/application/nginx-1.12.2

#编辑配置文件:
vim /application/nginx-1.12.2/conf/nginx.conf

二、建立环境

mkdir -p /application/nginx-1.12.2/html/{www,bbs,blog}
for name in www bbs blog;do echo $name.etiantian.org >/application/nginx-1.12.2/html/$name/index.html ;done
for name in www bbs blog;do cat /application/nginx-1.12.2/html/$name/index.html ;done

#www,bbs,blog为建立的三个名称

三、检查语法并重启

  任何修改配置文件的行为必须都要重启nginx才能生效。

/application/nginx-1.12.2/sbin/nginx -t
/application/nginx-1.12.2/sbin/nginx -s reload 

  补充,重启nginx的两种方式:


#优雅的重启nginx √√√√√√
/application/nginx-1.12.2/sbin/nginx  -s reload 

#关闭nginx 而后开启
/application/nginx-1.12.2/sbin/nginx  -s stop 
/application/nginx-1.12.2/sbin/nginx  

四、测试

Windows测试:

#1)修改 \etc\hosts 
10.0.0.200  www.etiantian.org bbs.etiantian.org blog.etiantian.org 

#2)浏览器测试 

linux测试:

curl -vH Host: www.etiantian.org 10.0.0.200

五、多个网站搭建

  上述咱们讲述了www.etiantian.org网站的搭建流程,如何将bbs.etiantian.org和blog.etiantian.org也搭建出来呢?只须要在配置文件多添加相应的配置便可。以下:

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.etiantian.org;
        location / {
            root   html/www;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {      
        listen       80;
        server_name  bbs.etiantian.org;
        location / {
            root   html/bbs;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }   
    server {      
        listen       80;
        server_name  blog.etiantian.org;
        location / {
            root   html/blog;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }   

}
相关文章
相关标签/搜索