---
title: "Nginx 的使用"
author: "hunter090730"
date: "2012-09-29T12:46:58Z"
tags: []
categories: ["Web前端"]
slug: "nginx"
draft: false
lastmod: "2012-11-30T15:39:41Z"
id: 1688498
url: "https://hunter090730.iteye.com/blog/1688498"
---

0 下载安装
 sudo sudo agt-get install nginx
1,修改配置文件

sudo vim /etc/nginx/sites-available/default

server {

        listen   80; ## listen for ipv4
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6

        server_name  localhost;

        access_log  /var/log/nginx/localhost.access.log;

        location / {
                root   /home/jimmy/web;
                index  index.html index.htm;
                autoindex on;
        }
2,安装nginx时，系统会为运行该软件添加一用户和组www-data
/etc/nginx/nginx.conf
3,给予web目录相应权限
sudo chown -R www-data:www-data /home/wanghao/web

sudo chmod 777 /home/jimmy/web

4,启动Nginx
jimmy@jimmy:~$ /etc/init.d/nginx stats
Usage: nginx {start|stop|restart|reload|force-reload|status|configtest}

jimmy@jimmy:~$ sudo /etc/init.d/nginx stop
[sudo] password for jimmy: 
Stopping nginx: nginx.
jimmy@jimmy:~$ sudo /etc/init.d/nginx start

假设：/home/jimmy/web/demo.htm
则访问demo.htm的url如下：
http://localhost/demo.htm or http://10.36.64.159/demo.htm
