unbuntu14.04 安装nginx配置
记录一下linux下安装nginx的所需要的配置。
首先从 nginx官网 下载所需要的版本,复制链接,执行
wget http://nginx.org/download/nginx-1.8.0.tar.gz
在你的linux目录下会有nginx-1.8.0.tar.gz压缩包,解压到当前目录。
tar -zxvf nginx-1.8.0.tar.gz cd nginx-1.8.0/ ./configure
这个时候一般会出现错误,我们需要安装nginx所依赖的包
sudo apt-get install gcc g++ make automake python perl
一般这个时候只是./configure的时候还会出现错误
./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option.
这个时候我们需要安装PCRE所需要的包。
sudo apt-get update sudo apt-get install libpcre3 libpcre3-dev sudo apt-get install openssl libssl-dev
现在执行./configure就成功了。
最后,我们进行编译和安装。
sudo make sudo make install
ok,安装结束。
安装完成以后,你可以输入命令启动服务器。
sudo /usr/local/nginx/sbin/nginx
这样,你就可以在网页输入localhost访问到web服务器。
你可以更改 /usr/local/nginx/html/index.html中的内容。如果想要关闭nginx.直接输入命令
pkill nginx
为了方便管理,我们可以写成shell脚本loadNginx.sh(自己取的文件名)来开关nginx。
#!/bin/bash if [ "$1" == "start" ];then sudo /usr/local/nginx/sbin/nginx echo "start..." elif [ "$1" == "stop" ];then sudo pkill nginx echo "stop..." fi
通过 bash loadNginx.sh start来开启nginx,bash loadNginx.sh stop 关闭。
也可以修改nginx的端口。
vim /usr/local/nginx/conf/nginx.conf
找到80端口,修改成8080(这是我自己选取的)。