linux系统安装nginx环境 配置项目站点

步骤一:构建Nginx服务器

1)使用源码包安装nginx软件包

[root@proxy ~]# yum -y install gcc pcre-devel openssl-devel        //安装依赖包
   wget http://nginx.org/download/nginx-1.10.3.tar.gz //下载压缩包
[root@proxy ~]# useradd -s /sbin/nologin nginx    //创建执行用户
[root@proxy ~]# tar  -xf   nginx-1.10.3.tar.gz   //解压
[root@proxy ~]# cd  nginx-1.10.3  
[root@proxy nginx-1.10.3]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-stream

备注:{
--prefix=/usr/local/nginx   \                //指定安装路径
--user=nginx   \                            //指定用户
--group=nginx  \                            //指定组
--with-http_ssl_module                        //开启SSL加密功能
--with-stream                   //开启TCP/UDP代理模块
}

[root@proxy nginx-1.10.3]# make && make install    //编译并安装

如果报错:./configure: error: the HTTP rewrite module requires the PCRE library.:
安装pcre-devel解决问题:yum -y install pcre-devel

如果再报错:./configure: error: the HTTP cache module requires md5 functions from OpenSSL library.You can …

  1. 安装openssl解决问题:yum -y install openssl openssl-devel
  2. 加参数执行命令:./configure --prefix=/usr/local/nginx

2)nginx命令的用法

1.[root@proxy ~]# /usr/local/nginx/sbin/nginx                    //启动服务
2.[root@proxy ~]# /usr/local/nginx/sbin/nginx -s stop            //关闭服务
3.[root@proxy ~]# /usr/local/nginx/sbin/nginx -s reload        //重新加载配置文件
4.[root@proxy ~]# /usr/local/nginx/sbin/nginx -V                //查看软件信息
5.[root@proxy ~]# ln -s /usr/local/nginx/sbin/nginx /sbin/        //方便后期使用

步骤二:修改服务器文件配置

修改nginx配置文件 (每次修改后记得使用‘/usr/local/nginx/sbin/nginx -s reload’重新加载nginx)
vim /usr/local/nginx/conf/nginx.conf

1.[root@aaa ~]# vim /usr/local/nginx/conf/nginx.conf
2... ..//html站点
3.server {
4.        listen       80;
5.        server_name  localhost;
6.        location / {
7.            root   html;
8.            index  index.html index.htm;
9.        }
10.  }
11. .....//PHP站点
12. server
    {
        listen 80;
        server_name www.aaa.com; ///域名加入hosts文件中
        root  www/one/public;
        location / {
            index  index.php;
            #autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

一个server代表一个站点的配置

修改host文件

vim /etc/hosts
```c
127.0.0.1   www.aaa.com

(如果站点搭建了TP框架,可能会出现runtime文件没有权限问题,使用‘chmod -R 777 runtime’就可以了)
还有PHP系统会自带一个5.4版本,如果要安装其他版本的话感觉很麻烦,但是不安装又不行
PHP安装完之后启动php-fpm然后就行了,只要NGINX环境搭建的没有问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值