Nginx WEB 安装

首先要安装pcre库

yum -y install pcre-devel pcre

下载源码包

http://nginx.org/download/nginx-1.4.2.tar.gz

解压源码包

tar -xzvf nginx-1.4.2.tar.gz

进入Nginx的目录修改其版本

cd nginx-1.4.2 ; sed -i -e ‘s/1.4.2//g’ -e ‘s/nginx\//WS/g’ -e
‘s/”NGINX”/”WS”/g’ src/core/nginx.h

./configure 出错

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using –with-openssl= option.

解决
yum install openssl openssl-devel -y

make &&make install

编译完成

/usr/local/nginx/sbin/nginx -t 检查 nginx 配置文件是否正
确,返回 OK 即正确。
[root@localhost nginx-1.4.2]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动Nginx

/usr/local/nginx/sbin/nginx

浏览器输入IP地址 出现Nginx的欢迎页面,表示源码编译Nginx成功。

Nginx配置虚拟主机

进入要配置的目录
cd /usr/local/nginx/conf
添加网站信息
vim nginx.conf

server {
        listen          80;
        server_name     www.a.com;

        location / {
            root   html/a;
            index  index.html index.htm;
        }
   }

    server {
        listen          80;
        server_name     www.b.com;

        location / {
            root   html/b;
            index  index.html index.htm;
        }
    }

,有些网站,你得需要用户和密码才能访问的,那么这样的网址需要怎么配置呢,其实也很简单,
第一步
在nginx.conf配置文件里添加相关配置如下

server {
        listen          80;
        server_name     www.b.com;

        location / {
            root   html/b;
            index  index.html index.htm;
            auth_basic  "oldboy tranning";
            auth_basic_user_file /usr/local/nginx/conf/htpasswd;
        }
    }

在当前网站的目录下执行
yum -y install httpd
which htpasswd
htpasswd -bc /usr/local/nginx/conf/htpasswd oldboy 123456
chmod 400 /usr/local/nginx/conf/htpasswd
chown nginx /usr/local/nginx/conf/htpasswd

若是有报错
[root@www html]# /etc/init.d/nginx -s reload
nginx: [error] invalid PID number “” in “/usr/local/nginx/logs/nginx.pid”

解决办法是:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

转载于:https://www.cnblogs.com/sujc-blogs/p/9722507.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值