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

nginx安装+虚拟主机配置

时间:2014-10-25 12:04:20      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   os   ar   for   strong   sp   文件   


安装

(1)在线安装

    $sudo apt-get install nginx

    Nginx的版本是1.2.1

    ubuntu安装Nginx之后的文件结构大致为:

     所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available下

    启动程序文件在/usr/sbin/nginx

    日志放在了/var/log/nginx中,分别是access.log和error.log

    并已经在/etc/init.d/下创建了启动脚本nginx

     默认的虚拟主机的目录设置在了/usr/share/nginx/www

(2)源码安装也比较简单,所有文件默认放到/usr/local/nginx目录,也可以自己指定位置

启动

   (1)在线安装的启动过程

      $sudo /etc/init.d/nginx start    #或者下面

      sudo service nginx start

   (2)源代码安装的启动过程

      $cd /usr/local/nginx

      $sbin/nginx

虚拟主机

(1)在site-ennable下面创建文件ubuntu.nobsu.net.conf文件,编辑如下:

server {
	listen       80;
	server_name ubuntu.nobsu.net;
	index index.html index.htm index.php;
	root  /data/www/ubuntu_nobsu_net;
 
	log_format ubuntu.nobsu.net ‘$remote_addr - $remote_user [$time_local] $request‘
	‘$status $body_bytes_sent $http_referer ‘
	‘$http_user_agent $http_x_forwarded_for‘;
	access_log  /data/log/ubuntu.nobsu.net.log ubuntu.nobsu.net;
}


(2)创建可访问目录

   /data/www/ubuntu_nobsu_net/index.html       

    hello nginx!!

(3)编辑测试域名:

        具体过程如下:

        1、修改hosts

        sudo gedit /etc/hosts

        2、添加解析记录( . )

        完整案例:127.0.0.1 localhost.localdomain localhost

        简洁记录:127.0.0.1 localhost

        3、保存后重启网络

        sudo /etc/init.d/networking restart

(4)访问:http://ubuntu.nobsu.net/  

         ok

[参考文献]

http://www.cnblogs.com/languoliang/archive/2013/04/01/nginx.html 安装

http://www.neoease.com/nginx-virtual-host/ 虚拟主机配置

nginx安装+虚拟主机配置

标签:style   blog   http   os   ar   for   strong   sp   文件   

原文地址:http://my.oschina.net/freegeek/blog/337189

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