[淋漓笔记]linux搭建nginx

1、下载nginx
命令:wget http://nginx.org/download/nginx-0.8.54.tar.gz

2、解压
命令:tar zxvf nginx-0.8.54.tar.gz

3、进入目录
命令:cd nginx-0.8.54

4、安装依赖包
命令:yum -y install gcc pcre-devel openssl openssl-devel (没有网络可在centos中找相关rpm)

5、执行 ./configure
命令:./configure

6、继续安装
命令:
make

make install

7、启动nginx服务
命令:/usr/local/nginx/sbin/nginx

8、重启nginx服务
命令:/usr/local/nginx/sbin/nginx -s reload

9、修改站点的配置文件
命令:vi /usr/local/nginx/conf/nginx.conf

10、多站点设置
⑴、在 /usr/local/nginx/conf/ 下创建 vhost 目录
命令:mkdir /usr/local/nginx/conf/vhost

⑵、在 /usr/local/nginx/conf/vhost 里创建一个名字为 linlik.conf 的文件,把站点配置文件写入(请查看最下面的站点内容)
命令:vi /usr/local/nginx/conf/vhost/linlik.conf

⑶、打开 /usr/local/nginx/conf/nginx.conf 文件,在相应位置加入 include 把以上2个文件包含进来
在页尾后括号上面加入一句:include vhost/*.conf; 然后保存退出并重启nginx服务

11、多站点的站点配置文档内容
如下:

server
{
listen 80;

listen [::]:80;

    server_name jiahaolin.com www.jiahaolin.com;
    index index.html index.htm index.php default.html default.htm default.php;
    root  /www/jiahaolin;

    include emlog.conf;
    #error_page   404   /404.html;
    location ~ [^/]\.php(/|$)
        {
            # comment try_files $uri =404; to enable pathinfo
            try_files $uri =404;
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
            #include pathinfo.conf;
        }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

    location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

    access_log  /home/wwwlogs/jiahaolin.com.log  access;
}

[淋漓笔记]linux搭建nginx:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter