阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux中配置Nginx Web服务器过程

148次阅读
没有评论

共计 2879 个字符,预计需要花费 8 分钟才能阅读完成。

Linux 系统环境:CentOS 7

需要软件:nginx-1.3.16.tar.gz  libevent-2.0.21-stable.tar.gz  Pcre 和 pcre-devel

nginx 下载地址:http://nginx.org/download/nginx-1.3.16.tar.gz

libevent 下载地址:http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

Project 1:安装 Nginx 及配置环境

Step 1:安装 pcre-devel,以及建立 nginx 用户

# yum install pcre-devel

# groupadd -r nginx

# useradd -r -g nginx -M nginx

Step 2:解压缩 nginx 的源码并安装

# tar -zxvf nginx-1.3.16.tar.gz -C /usr/local/src/

# cd /usr/local/src/nginx-1.3.16/

# ./configure \

–conf-path=/etc/nginx/nginx.conf \

–error-log-path=/var/log/nginx/error.log \

–http-log-path=/var/log/nginx/access.log \

–pid-path=/var/run/nginx/nginx.pid \

–lock-path=/var/lock/nginx.lock \

–user=nginx \

–group=nginx \

–with-http_ssl_module \

–with-http_flv_module \

–with-http_stub_status_module \

–with-http_gzip_static_module \

–http-client-body-temp-path=/var/tmp/nginx/client/ \

–http-proxy-temp-path=/var/tmp/nginx/proxy/ \

–http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \

–with-pcre

# make && make install

# mkdir -p /var/tmp/nginx/client

Step 3: 启动 Nginx 服务并在客户端做测试

# /usr/local/nginx/sbin/nginx

在浏览器上输入本机 ip

Project 2:实现虚拟主机

Step 1:准备工作

# ifconfig eth0:0 192.168.111.20

建立两个站点目录

# mkdir /website1

# mkdir /website2

建立两个存放日志的目录

# mkdir /var/log/nginx/website1

# mkdir /var/log/nginx/website2

创建两个测试页

# echo “This is website1” >/website1/index.html

# echo “This is website2” >/website2/index.html

Step 2:修改配置文件,原有的配置文件中默认有一个 server 节点,修改一下,然后再添加一个 server 节点

server {

listen 192.168.111.10:80;

server_name localhost;

#charset koi8-r;

access_log /var/log/nginx/website1/access.log;

error_log /var/log/nginx/website1/error.log;

location / {

root /website1;

index index.html index.htm;

}

error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

server {

listen 192.168.111.20:80;

server_name localhost;

#charset koi8-r;

access_log /var/log/nginx/website2/access.log;

error_log /var/log/nginx/website2/error.log;

location / {

root /website2;

index index.html index.htm;

}

error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

此文件在 Nginx 安装目录下的 conf 里面的 nginx.conf 里面修改

Step 3:s 使用 ./nginx -s reload 重新装在配置

在终端里面进入到 nginx 目录下的 sbin,然后使用:./nginx -s reload 命令进行重新装载配置

更多 Nginx 相关教程见以下内容

CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm

Ubuntu 16.04 LTS 上安装 Nginx、MariaDB 和 HHVM 运行 WordPress http://www.linuxidc.com/Linux/2016-10/136435.htm

Nginx 安装配置使用详细笔记 http://www.linuxidc.com/Linux/2014-07/104499.htm

Linux(RHEL7.0)下安装 Nginx-1.10.2 http://www.linuxidc.com/Linux/2016-10/136484.htm

Nginx 日志过滤 使用 ngx_log_if 不记录特定日志 http://www.linuxidc.com/Linux/2014-07/104686.htm

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里 

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-01/139339.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计2879字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中