好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

阿里云linux服务器配置安装nginx - linux教程

阿里云linux服务器配置安装nginx

一朋友买了一台linux的阿里云机器了,但是不知道怎么安装配置WEB环境了,下面我就来给各位介绍一下在阿里云linux中配置nginx环境的方法,希望例子能给各位带来帮助

1.首先下载pcre-8.32.tar.gz和nginx-1.4.7.tar.gz最新稳定版本 

2.安装 pcre 让nginx支持rewrite 

pcre-8.32.tar.gz 上传到/home 目录下面 

1) 解压 pcre 

执行#tar -zxvf pcre-8.32.tar.gz 解压 pcre 后 /home 下面会有 pcre-8.32 文件夹 

2)配置pcre 

执行#cd /home/pcre-8.32 

执行#./configure 检查当前的环境是否满足要安装软件的依赖关系,如果出现错误checking for a BSD-compatible install… /usr/bin/install -c

执行#yum install gcc gcc-c++

3)make 自动完成编译工作

4)安装

在linux 中输入 make install 正式安装

3.安装 nginx

nginx-1.4.7.tar.gz 上传到/home 目录下面

1) 解压 nginx

执行#tar -zxvf nginx-1.4.7.tar.gz 解压 nginx 后 /home 下面会有nginx-1.4.7 文件夹 

2 配置nginx 

执行#cd nginx-1.4.7 

执行#./configure –prefix=/usr/local/nginx –with-http_stub_status_module 

///–prefix=/usr/local/nginx是指定nginx的安装路径 

其中参数 –with-http_stub_status_module 是为了启用 nginx 的 NginxStatus 功能,用来监控 Nginx 的当前状态.

3)make

在linux 中执行#make 

4)安装 

在linux 中执行#make install 

5) 检查是否安装成功 

执行#cd /usr/local/nginx/sbin 

执行#./nginx -t 

结果显示:

nginx:the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok 

nginx:configuration file /usr/local/nginx/conf/nginx.conf test is successful 

安装成功 

6)启动nginx 

执行#cd /usr/local/nginx/sbin 目录下面 执行#./nginx 启动 nginx 

7 )检查是否启动成功 

ie 浏览器中输入服务器ip 例如http://115.124.22.59 

安装过程中出现的错误:1没有安装 zlib-devel,提示错误 the HTTP gzip module requires the zlib library.

解决: 执行#yum install -y zlib-devel 

2出现lib文件找不到,原因是创建的lib文件和nginx查找的文件名不统一导致

错误./nginx: error while loading shared libraries:

libpcre.so.1: cannot open shared object file: No such file or directory

阿里云linux服务器配置nginx

1,配置站点

打开配置文件目录找到nginx.conf:执行#cd /usr/local/nginx/conf ,编辑nginx.conf:执行#vi nginx.conf ,找到如下配置:

  • server {  
  • listen 80;  
  • server_name localhost; //把 localhost改成你的域名 例如www.qiyedun.com qiyedun.com  
  • #charset koi8-r;  
  • #access_log logs/host.access.log main;  
  • location / {  
  • root /mnt/wordpress; //root跟着路径就是你项目的放置路径,千万别搞错了。  
  • index   index .php  index .html  index .htm; // index 跟着默认首页,添加多个nginx会挨个查找,直到找到对应的。  
  • 2,配置多站点

    方法1:编辑vi nginx.conf

    找到server 拷贝一份放到http{}里面;也可以复制我如下代码放到http{}里面.

  • server { 
  • listen 80; 
  • server_name second .phpfensi.com; //第N个站点的域名,也可以是二级域名,例如: second .qiyedun.com 
  • #charset koi8-r; 
  • #access_log logs/host.access.log main; 
  • location / { 
  • root /mnt/wordpress; // 第N个站点站点的文件存放位置 
  • index   index .html  index .htm; 
  • }  --phpfensi.com  
  • #error_page 404 /404.html; 
  • # redirect server error pages to  the  static  page /50x.html 
  • error_page 500 502 503 504 /50x.html; 
  • location = /50x.html { 
  • root html; 
  • 方法二:和第一个中配置是一样的原理,只是为了更好的管理多个站点,很多个站点建议用第二中配置方法.

    nginx的默认安装路径为/usr/local/nginx

    打开nginx文件夹下的配置文件夹 执行#cd /usr/local/nginx/conf 

    查看conf文件夹下的文件 执行#ll //ll是LL的小写 ,不是123的1不要搞错了 

    编辑nginx.conf 执行#vi nginx.conf //在http{}里面最下端添加include /usr/local/nginx/conf/vhosts/*.conf; 

    打开 /usr/local/nginx/conf 执行#cd /usr/local/nginx/conf 

    创建vhosts文件夹 执行#mkdir vhosts 

    例如你有第二站点域名为www.phpfensi.com 

    进入vhost 执行#cd /usr/local/nginx/conf/vhosts 

    创建配置文件 执行#vi qiyedun.conf 

    拷贝如下代码:

  • server {  
  • listen 80;  
  • server_name second .qiyedun.com; //第N个站点的域名,也可以是二级域名,例如: second .qiyedun.com  
  • #charset koi8-r;  
  • #access_log logs/host.access.log main;  
  • location / {  
  • root /mnt/wordpress; // 第N个站点站点的文件存放位置  
  • index   index .html  index .htm;  
  • }  
  • #error_page 404 /404.html;  
  • # redirect server error pages to  the  static  page /50x.html  
  • #  
  • error_page 500 502 503 504 /50x.html;  
  • location = /50x.html {  
  • root html;  
  • }  
  • }  

    保存qiyedun.conf,重启nginx 执行#/usr/local/nginx/sbin/nginx -s reload.

    查看更多关于阿里云linux服务器配置安装nginx - linux教程的详细内容...

  •   阅读:75次