1.安装pcre:
查看是否安装过pcre:
[root@hongyaClient01 ~]# rpm -qa pcrepcre-devel
pcre-7.8-6.el6.x86_64
若没有则执行安装命令:[root@hongyaClient01 ~]# yum install pcre-devel -y
[root@hongyaClient01 ~]# rpm -qa pcrepcre-devel
pcre-7.8-7.el6.x86_64
pcre-devel-7.8-7.el6.x86_64
2.安装安全软件包openssl:
[root@hongyaClient01 ~]# yum installopenssl-devel -y
[root@hongyaClient01 ~]# rpm -qa opensslopenssl-devel
openssl-devel-1.0.1e-48.el6_8.1.x86_64
openssl-1.0.1e-48.el6_8.1.x86_64
3.安装nginx:
[root@hongyaClient01 ~]# mkdir -p/home/oldboy/tools
[root@hongyaClient01 ~]# cd /home/oldboy/tools
[root@hongyaClient01 tools]# wget -qhttp://nginx.org/download/nginx-1.6.3.tar.gz
[root@hongyaClient01 tools]# ls nginx-1.6.3.tar.gz
nginx-1.6.3.tar.gz
[root@hongyaClient01 tools]# ls nginx-1.6.3.tar.gz -lk
-rw-r--r-- 1 root root 787 4月 8 2015 nginx-1.6.3.tar.gz
解压并切换到nginx目录:
[root@hongyaClient01 tools]# tar zxfnginx-1.6.3.tar.gz
[root@hongyaClient01 tools]# cd nginx-1.6.3
查看总共文件个数:
[root@hongyaClient01 nginx-1.6.3]# tree|wc-l
404
编译并安装(--prefix 编译目录)
[root@hongyaClient01nginx-1.6.3]# ./configure --prefix=/application/nginx-1.6.3 --user=nginx--group=nginx --with-http_ssl_module --with-http_stub_status_module
[root@hongyaClient01 nginx-1.6.3]#make&& make install
添加用户:
[root@hongyaClient01 nginx-1.6.3]# useradd nginx -s /sbin/nologin -M
[root@hongyaClient01 nginx-1.6.3]# id nginx
uid=502(nginx) gid=502(nginx) 组=502(nginx)
[root@hongyaClient01 tools]# ll /application/nginx-1.6.3/ -ld
drwxr-xr-x 6 root root 4096 7月 17 19:15/application/nginx-1.6.3/
创建软连接:
[root@hongyaClient01 tools]# ln -s/application/nginx-1.6.3/ /application/nginx
[root@hongyaClient01 tools]# ls -l/application/
总用量 8
lrwxrwxrwx 1 root root 25 7月 17 19:20 nginx ->/application/nginx-1.6.3/
drwxr-xr-x 6 root root 4096 7月 17 19:15 nginx-1.6.3
启动nginx服务:
[root@hongyaClient01 ~]# ps -ef|grep nginx|grep -v grep
root 10949 1 0 19:26 ? 00:00:00 nginx: master process/application/nginx/sbin/nginx
nginx 10950 10949 0 19:26 ? 00:00:00 nginx: worker process
[root@hongyaClient01 ~]# ss -lntup|grep nginx
tcp LISTEN 0 128 *:80 *:* users:(("nginx",10949,6),("nginx",10950,6))
本地测试是否部署成功:
[root@hongyaClient01 ~]# curl 127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome tonginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginxweb server is successfully installed and
working. Further configuration isrequired.</p>
<p>For online documentation andsupport please refer to
<ahref="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<ahref="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for usingnginx.</em></p>
</body>
</html>
[root@hongyaClient01 ~]#/application/nginx/sbin/nginx -V
nginx version: nginx/1.6.3
built by gcc 4.4.7 20120313 (Red Hat4.4.7-11) (GCC)
TLS SNI support enabled
configure arguments:--prefix=/application/nginx-1.6.3 --user=nginx --group=nginx--with-http_ssl_module --with-http_stub_status_module
切换到安装目录并查看:
[root@hongyaClient01 nginx]# ls -l|grep -vtemp
总用量 36
drwxr-xr-x 2 root root 4096 7月 17 19:15 conf
drwxr-xr-x 2 root root 4096 7月 17 19:15 html
drwxr-xr-x 2 root root 4096 7月 17 19:26 logs
drwxr-xr-x 2 root root 4096 7月 17 19:15 sbin
查看nginx核心配置文件:
[root@hongyaClient01 html]# cd ..
[root@hongyaClient01 nginx]# cd conf/
[root@hongyaClient01 conf]# ls -lnginx.conf
-rw-r--r-- 1 root root 2656 7月 17 19:15 nginx.conf
最小化配置基于域名的nginx的配置文件:
[root@hongyaClient01 conf]# egrep -v"#|^$" nginx.conf.default
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 localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[root@hongyaClient01 conf]# egrep -v"#|^$" nginx.conf.default >nginx.conf
编辑nginx.conf文件:
[root@hongyaClient01 conf]# vim nginx.conf
location = /50x.html {
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
root html/www server {
listen 80;
server_name www.hongya.org;
location / {
root html/www;
index index.html index.htm;
}
root html/www;
erver {
listen 80;
server_name www.hongya.org;
location / {
root html/www;
index index.html index.htm;
}
server {
listen 80;
server_name www.hongya.org;
location / {
root html/www;
index index.html index.htm;
}
}
erver {
listen 80;
server_name www.hongya.org;
location / {
root html/www;
index index.html index.htm;
}
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.hongya.org;
location / {
root html/www;
index index.html index.htm;
}
}
server {
listen 80;
server_name bbs.hongya.org;
location / {
root html/bbs;
index index.html index.htm;
}
}
}
"nginx.conf" 32L, 566C 已写入
创建目录及html页面:
[root@hongyaClient01 conf]# mkdir../html/{www,bbs}
[root@hongyaClient01 conf]# ls -l ../html/
总用量 16
-rw-r--r-- 1 root root 537 7月 17 19:15 50x.html
drwxr-xr-x 2 root root 4096 7月 17 21:31 bbs
-rw-r--r-- 1 root root 628 7月 17 19:48 index.html
drwxr-xr-x 2 root root 4096 7月 17 21:31 www
[root@hongyaClient01 conf]#
[root@hongyaClient01 conf]# echo"www.hongya.org" >../html/www/index.html
[root@hongyaClient01 conf]# echo"bbs.hongya.org" >../html/bbs/index.html
[root@hongyaClient01 conf]# cat../html/{www,bbs}/index.html
www.hongya.org
bbs.hongya.org
检查配置是否有误:
[root@hongyaClient01 conf]#/application/nginx/sbin/nginx -t
nginx: the configuration file/application/nginx-1.6.3/conf/nginx.conf syntax is ok
nginx: configuration file/application/nginx-1.6.3/conf/nginx.conf test is successful
重启nginx服务:
[root@hongyaClient01 conf]#/application/nginx/sbin/nginx -s reload
配置host文件,测试:
[root@hongyaClient01 conf]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.132 www.hongya.org
192.168.10.132 bbs.hongya.org
~
"/etc/hosts" 5L, 221C 已写入
基于端口的nginx配置:
原文地址:http://hongya.blog.51cto.com/5179466/1869947