搭建nginx虚拟主机
[[email protected] ~]# cat /etc/redhat-release 查看系统版本号 CentOS release 6.6 (Final) [[email protected] ~]# uname -r //print the kernel release 2.6.32-504.el6.x86_64 [[email protected] ~]# uname -m // print the machine hardware name x86_64 [[email protected] ~]# rpm -qa gcc gcc-c++ gcc-4.4.7-11.el6.x86_64 gcc-c++-4.4.7-11.el6.x86_64 [[email protected] ~]# rpm -qa pcre pcre-devel [[email protected] ~]# rpm -qa openssl openssl-devel [[email protected] ~]# rpm -qa pcre pcre-devel openssl openssl-devel [[email protected] nginx-1.6.3]# wget http://nginx.org/download/nginx-1.6.3.tar.gz 下载安装包 [[email protected] nginx-1.6.3]# ls 确认安装包下载成功 [[email protected] nginx-1.6.3]# tar -zxvf nginx-1.6.3.tar.gz 解压 [[email protected] nginx-1.6.3]# ls 查看解压结果 [[email protected] nginx-1.6.3]# cd nginx-1.6.3 [[email protected] nginx-1.6.3]# ./configure --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module 自定义安装配置 [[email protected] nginx-1.6.3]# make && make install 编译安装 [[email protected] nginx-1.6.3]# echo $? 查看执行结果 0 成功 [[email protected] nginx-1.6.3]# useradd nginx -s /sbin/nologin -M 创建用户 uid=500(nginx) gid=500(nginx) groups=500(nginx) [[email protected] nginx-1.6.3]# ll /application/nginx-1.6.3/ [[email protected] nginx-1.6.3]# ln -s /application/nginx-1.6.3/ /application/nginx 为了方便使用,做软链接 [[email protected] nginx-1.6.3]# /application/nginx/sbin/nginx 启动服务 [[email protected] nginx-1.6.3]# ps -ef |grep nginx |grep -v grep 查看服务进程 [[email protected] nginx-1.6.3]# netstat -lntup |grep nginx 端口是80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN [[email protected] nginx-1.6.3]# curl 127.0.0.1 测试本地 浏览器登录测试成功。 |
配置Nginx虚拟主机:
虚拟主机: [[email protected] ~]# cd /application/nginx/conf [[email protected] conf]# cp nginx.conf /data/root/backup/ 备份nginx.conf配置文件 将nginx.conf.default中没有注释、不是空白行的内容导出到nginx.conf [[email protected] conf]# mkdir ../html/www [[email protected] conf]# cat ../html/{www,bbs,blog}/index.html [[email protected] conf]# vim nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" "$http_x_forwarded_for"‘; access_log logs/access.log main; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.etiantian.org alias etiantian.org; access_log /app/logs/www_logs/access_www.log main; 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; access_log /app/logs/bbs_logs/access_bbs.log main; 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; access_log /app/logs/blog_logs/access_blog.log main; location / { root html/blog; index index.html index.htm; } [[email protected] conf]# vim /etc/hosts 192.168.10.104 www.etiantian.org etiantian.org [[email protected] conf]# /application/nginx/sbin/nginx -t [[email protected] conf]# ll /app/logs/bbs_logs/ [[email protected] conf]# ll /app/logs/www_logs/ |