码迷,mamicode.com
首页 > 其他好文 > 详细

安装nginx 配置虚拟主机

时间:2017-06-27 23:38:53      阅读:364      评论:0      收藏:0      [点我收藏+]

标签:openssl   dir   not found   list   http   wan   listen   log   stop   

nginx安装

#查看操作系统版本
[root@master1 ~]# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 
#查看内核版本和64位还是32位
[root@master1 ~]# uname -a
Linux master1 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

#关闭selinux
#临时关闭
[root@master1 sbin]# getenforce 
Enforcing
[root@master1 sbin]# setenforce 0
[root@master1 sbin]# getenforce 
Permissive
#永久关闭
[root@master1 sbin]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/selinux/config 

#关闭iptables
#临时关闭
[root@master1 sbin]# systemctl stop firewalld.service
#开机不启动(永久关闭)
[root@master1 sbin]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

#yum进行依赖解决
[root@master1 ~]# yum install openssl openssl-devel -y #openssl使用https服务的时候要用此模块
[root@master1 ~]# yum install pcre pcre-devel -y  #使nginx支持URI重写的rewrite模块

#安装nginx依赖检查  
[root@master1 ~]# rpm -qa  openssl openssl-devel pcre pcre-devel
pcre-8.32-15.el7_2.1.x86_64
openssl-devel-1.0.1e-60.el7_3.1.x86_64
pcre-devel-8.32-15.el7_2.1.x86_64
openssl-1.0.1e-60.el7_3.1.x86_64

#获得安装介质
[root@master1 home]# mkdir -p /home/wangyp/tools
[root@master1 home]# cd /home/wangyp/tools/
[root@master1 tools]# wget http://nginx.org/download/nginx-1.12.0.tar.gz

#创建用户
[root@master1 tools]# useradd nginx -s /sbin/nologin  -M

[root@master1 tools]# tar -zxf nginx-1.12.0.tar.gz
[root@master1 nginx-1.12.0]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.12.0/ --with-http_stub_status_module --with-http_ssl_module 
checking for OS
 + Linux 3.10.0-514.el7.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found
##需要安装编译器
##yum进行编译器的安装
[root@master1 nginx-1.12.0]# yum -y install gcc gcc-c++ autoconf automake make
##--user --group指定用户  --prefix指定安装路径  --with-http激活两个模块(一个监控的,一个ssl支持的)可通过[root@master1 nginx-1.12.0]# ./configure --help进行查看 enable ngx_http_stub_status_module   enable ngx_http_ssl_module
[root@master1 nginx-1.12.0]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.12.0/ --with-http_stub_status_module --with-http_ssl_module 
[root@master1 nginx-1.12.0]# make
[root@master1 nginx-1.12.0]# make install
[root@master1 nginx-1.12.0]# ln -s /application/nginx-1.12.0 /application/nginx

##检查并启动nginx
[root@master1 sbin]# ./nginx -t
nginx: the configuration file /application/nginx-1.12.0//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.12.0//conf/nginx.conf test is successful
[root@master1 sbin]# /application/nginx/sbin/nginx 
[root@master1 sbin]# lsof -i :80
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   13236  root    6u  IPv4 159539      0t0  TCP *:http (LISTEN)
nginx   13237 nginx    6u  IPv4 159539      0t0  TCP *:http (LISTEN)
[root@master1 sbin]# ps -ef | grep nginx
root     13236     1  0 10:26 ?        00:00:00 nginx: master process /application/nginx/sbin/nginx
nginx    13237 13236  0 10:26 ?        00:00:00 nginx: worker process
root     13241 10440  0 10:27 pts/0    00:00:00 grep --color=auto nginx


##测试 wget&curl两个命令都可以
[root@master1 sbin]# wget 127.0.0.1
--2017-06-27 10:32:33--  http://127.0.0.1/
正在连接 127.0.0.1:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:612 [text/html]
正在保存至: “index.html”

100%[===============================================================================================================================>] 612         --.-K/s 用时 0s      

2017-06-27 10:32:33 (86.8 MB/s) - 已保存 “index.html” [612/612])

[root@master1 sbin]# curl 127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</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 nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

  

 

[root@master1 conf]# more nginx.conf
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.loveurself.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.loveurself.org;
        location / {
            root   html/bbs;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

  

 

压力测试工具:

webenche

安装nginx 配置虚拟主机

标签:openssl   dir   not found   list   http   wan   listen   log   stop   

原文地址:http://www.cnblogs.com/wanyp/p/7087464.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!