优班图安装nginx编译环境
㈠ ubuntu 16.04下怎样安装nginx
2种方法:
1,apt-get install nginx
2,网上下载nginx安装包,然后编译
㈡ 如何在ubuntu下 安装nginx服务器
获取nginx源码
1、打开网络在搜索栏输入nginx找到nginx官网,点击进入;
2、点击最新发布版,进入下载地址;
3、找到最新源码,右击获取源码下载地址通过wget下载;
如何在ubuntu下 安装nginx服务器
如何在ubuntu下 安装nginx服务器
如何在ubuntu下 安装nginx服务器
如何在ubuntu下 安装nginx服务器
配置编译安装
配置
./configure --prefix=/usr/local/nginx
编译、安装
make && make install
配置过程可能出现:
错误描述:error: the HTTP rewrite mole requires the PCRE library
解决方法:
需要安装pcre包。
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
你可能还需要安装
sudo apt-get install openssl libssl-dev
如何在ubuntu下 安装nginx服务器
如何在ubuntu下 安装nginx服务器
3
启动nginx
进入nginx安装目录,找到nginx目录所在目录,执行./nginx -c /usr/local/nginx/conf/nginx.conf启动服务;
在浏览器输入web服务器地址http://127.0.0.1,浏览器显示速度超级快,显示如图说明nginx安装启动成功
如何在ubuntu下 安装nginx服务器
㈢ 怎么编译安装nginx1.8.1
要编译安装Nginx,首先我们要安装依赖包 pcre-devel 和 zlib-devel:
# yum install pcre-devel zlib-devel -y
程序默认是使用 nobody 身份运行的,我们建议使用 nginx 用户来运行,首先添加Nginx组和用户,不创建家目录,不允许登陆系统
# groupadd nginx
# useradd -M -s /sbin/nologin -g nginx nginx
准备工作完成后就是下载编译安装Nginx了,可以从我提供的网盘下载,也可以去Nginx的官网下载。
首先解压源码包:
# tar xf nginx-1.4.4.tar.gz
然后 cd 到解压后的目录就可以执行 ./configure 了
# cd nginx-1.4.4
指定安装目录和运行时用的属主和属组,并启用状态监控模块等
# ./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_mole \
--with-http_flv_mole \
--with-http_stub_status_mole \
--with-http_gzip_static_mole \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-pcre
等配置完成后就可以 make && make install 了
# make && make install
# mkdir /var/tmp/nginx/client/ -pv
等编译安装完成后在 /usr/local 下就会出现 Nginx 这个目录了,进入这个目录后发现目录非常简单。它的配置文件存放在 conf 目录中,网页文件存放在 html 中,日志文件存放在 logs 中,sbin 目录下只有一个可执行程序 "nginx"
接下来我们简单的为它提供一个服务脚本吧!
# vim /etc/init.d/nginx
新建文件/etc/rc.d/init.d/nginx,内容如下:
#!/bin/bash
# chkconfig:235 85 15
# description: Nginx is an HTTP server
. /etc/rc.d/init.d/functions
start() {
echo "Start..."
/usr/local/nginx/sbin/nginx &> /dev/null
if [ $? -eq 0 ];then
echo "Start successful!"
else
echo "Start failed!"
fi
}
stop() {
if killproc nginx -QUIT ;then
echo "Stopping..."
fi
}
restart() {
stop
sleep 1
start
}
reload() {
killproc nginx -HUP
echo "Reloading..."
}
configtest() {
/usr/local/nginx/sbin/nginx -t
}
case $1 in
start)
start ;;
stop)
stop ;;
restart)
restart ;;
reload)
reload ;;
configtest)
configtest ;;
*)
echo "Usage: nginx {start|stop|restart|reload|configtest}"
;;
esac
之后给这个文件可执行权限:
# chmod +x /etc/init.d/nginx
好了,现在可以使用 start,stop 这些参数控制Nginx服务了
由于脚本是我自己写的,还有许多不尽人意的地方,欢迎大家修改和完善!
现在我们就试试启动服务看看效果吧:
# service nginx start
记得关闭 SElinux 和 iptables 防火墙哦,
# service iptables stop
# setenforce 0
接下来就在浏览器中访问你服务的IP看看效果吧!是不是出项了欢迎的字样呢
接下来就研究下 Nginx 的配置文件吧!
# vim /usr/local/nginx/conf/nginx.conf
各项参数的意义如下:
worker_processes 1; 工作进程数量
error_log logs/error.log; 日志文件位置
pid logs/nginx.pid; pid文件位置
worker_connections 1024; 没进程的连接数
listen 80; 监听端口
server_name localhost; 主机名
root html; 网站根目录
index index.html index.htm; 网站索引页
error_page 500 502 503 504 /50x.html; 访问错误页面
剩下的其他被注释掉的代码块:
location ~ \.php$ { . . . . . . } 对PHP的支持,需要安装PHP
server { . . . . . . } 添加server代码块能添加虚拟主机
剩下还有监听443端口的超文本传输安全协议 HTTPS server 需要在编译Nginx时添加ssl的支持
接下来我们试着添加一台虚拟主机吧,虚拟主机的添加可以基于端口,可以基于IP,也可以基于主机名,我们挨个来看看:
基于端口:
首先编辑配置文件,添加server代码块,记得要写到http{ . . . . . . }这个大的代码块中。
server {
listen 8080;
server_name localhost;
location / {
root /var/www/html;
index index.html index.htm;
}
}
这样就添加了一个监听8080端口的服务,你也可以定义自己喜欢的端口哦。
接下来检查下配置文件有没有问题,如果最后一个单词显示successful就代表没问题了,可以重新启动Nginx了
# service nginx configtest
# service nginx restart
接下来就给第二个虚拟主机写一个index吧!首先创建目录
# mkdir -pv /var/www/html
# echo '<h1>Hi! This is 8080!</h1>' > /var/www/html/index.html
好了 接下来试着在浏览器中访问访问,记得第二个主机要加上端口访问哦
现在试着用不同的IP建立虚拟主机吧!我们可以在一块网卡上绑定多个IP地址的方式来实现
# ifconfig eth0:0 10.0.0.4/8
记得把IP换成你自己的哦!然后ifconfig看看是不是多出来一个网卡IP了呢
让后继续修改配置文件,这回要修改两个地方,一个是原本自带的站点的 listen 项,一个是自己添加的站点的 listen 项。
基于IP:
server {
listen 10.0.0.3:80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
}
server {
listen 10.0.0.4:80;
server_name localhost;
location / {
root /var/www/html;
index index.html index.htm;
}
}
让他们只监听不同的IP,用相同的端口
接下来再浏览器上用不同的IP来访问试试吧,及的还得重启Nginx,先检查一下,出现错误了看看哪里配置的不对,然后就可以重启了。
# service nginx congiftest
# service nginx restart
如果配置给网卡的第二个IP不想要了,把它停掉就可以了
# ifconfig eth0:0 down
再 ifconfig 看看是不是没有了呢
现在试试用不同的主机名吧!也是企业用的最多的方式。我们把两个站点的listen项都改为80,然后修改service_name项为定义的主机名
基于主机名:
server {
listen 80;
server_name ybmq.com;
location / {
root html;
index index.html index.htm;
}
}
server {
listen 80;
server_name zhzz.com;
location / {
root /var/www/html;
index index.html index.htm;
}
}
然后重启Nginx吧!
可是我们在浏览器上怎么通过域名访问呢?要知道我们访问 啊,qq 啊之类的是通过DNS服务器的,难道我们还要配置一台DNS服务器?其实不然,我们通过修改客户机的 hosts 文件就可以了。hosts文件是一个本地的域名解析文件,我们要解析哪些域名只要把域名和对应的IP写到一起就可以了。在Windows XP之后的系统中,这个文件位于:
C:\Windows\System32\drivers\etc\hosts
我们用文本编辑器打开,添加两个相同的IP对应的两个不同的主机名就可以了。
如下图所示
如果你打开这个文件发现已经有很多IP地址了,可以直接在最后加入这两行,也可以直接清空这个文件,不会有什么问题的。这个文件的用途还可以屏蔽一些网站哦,只需要把网址对于的IP改为 127.0.0.1 也就是本地回环地址,浏览器查询域名对应的IP时时先通过查询这个文件的,如果查询到了,不管对错都不会访问DNS服务器了,所以我们给它一个错误的地址,那它一辈子也打不开被屏蔽掉的网站了。
好了 接下来就在浏览器中试试用用域名访问你的两个站点吧。
如果大家还用IP访问会是什么情况呢?我不说了,大家还是自己测试吧 哈哈o(^▽^)o
㈣ ubuntu怎么编译nginx
先解压nginx的tar包,进入解压后的文件夹里,如果要安装到其他路径的话,修改configure文件里的prefix的值然后执行./configure,或者直接使用./configure --prefix=/xx/xx/xxx来指定,安装路径然后make -j2,如果你的处理器核多,可以增大数字,再然后就是make & make install了。
要注意的是./configure后面可以跟随很多参数配置:
比如,需要的话可以加上--config-path=/xx/xx/xxx/nginx.conf指定nginx的服务器配置文件路径;
--add-mole增加模块,比如luz、pagespeed、upstream等等,这些都可以在官网上查到。
㈤ 如何安装nginx
部署安装nignx的环境
yum-yinstallgccgcc-c++ncurses-devellibxml2-devel
openssl-develcurl-devellibjpeg-devellibpng-develautoconfpcre-devel
libtool-libsfreetype-develgdzlib-develzipunzip
-devel
glibc-develglibc-staticglib2-develbzip2-devel
gettext-devellibcap-devellogrotatentp
libmcrypt-develpatch
2.下载安装nginx
wgethttp://nginx.org/download/nginx-1.10.2.tar.gz--获取nignx安装包
tar-zxvf./nginx-1.10.2.tar.gz--解压安装包
cd./nginx-1.10.2
./configure
--with-stream---开启tcp代理
--with-http_ssl_mole---开启https
make---编译nginx
makeinstall--安装nginx
3.启动nginx
nginx启动命令(注意nginx默认使用80端口,如果80端口已经使用,请去nginx.conf修改默认端口)
/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf
4.yum安装nginx。
yum-yinstallnginx
servicenginxstart--启动nginx
servicenginxstop--停止nginx
servicenginxrestart--重启nginx
5.编译安装的nginx配置文件在/usr/local/nginx/conf/nginx.conf,网站在/usr/local/nginx/html/下面。yum安装的nginx配置文件在/etc/nginx/nginx.conf,网站在/var/www/html/下面
㈥ 在Ubuntu 里有没有什么命令确定 Nginx 配置文件位置
当你执行 nginx -t
得时候,nginx会去测试你得配置文件得语法,并告诉你配置文件是否写得正确,同时也告诉了你配置文件得路径:
# nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
㈦ 源码安装nginx需要安装哪些东西
nginx配置里面配置一个server段,然后把网站的目录,域名,别名等配置好就可以了。想要好管理配置,用include加个文单花厕拘丿饺搽邪敞矛件,里面专门配置server段
㈧ 如何编译安装nginx1.8.1
因素很多, 可能是版本不正确, 可能是系统环境没有安装好啊 ,。看看wo 的网名一下吧,一定能解决问题的啊 1
㈨ ubuntu怎么安装nginx
Nginx程序的稳定性来自于它采用了分阶段的资源分配技术,使得CPU与内存占用率会非常低,所以使用Nginx程序部署动态网站环境不仅十分的稳定、高效,而且消耗更少的系统资源,丰富的模块功能也几乎与Apache程序数量相同,现在已经完全的支持了proxy、rewrite、mod_fcgi、ssl、vhosts等常用模块。而且还支持了热部署技术,即能够可以7*24不间断提供服务,即便运行数月也无须重启,而且还可以在不暂停服务的情况下直接对Nginx服务程序进行升级。
坦白来讲,虽然Nginx程序的代码质量非常高,代码很规范,技术成熟,模块扩展也很容易,但Nginx依然存在不少问题,比如Nginx是由俄罗斯人创建的,所以在资料文档方面还并不完善,中文教材的质量更是鱼龙混杂,但Nginx近年来增长势头迅猛,预测未来应该能够在轻量级HTTP服务器市场有不错的未来。
安装PCRE(Perl兼容的正则表达式库,解压与编译过程已省略):
[root@linuxprobe ~]# cd /usr/local/src
[root@linuxprobe src]# mkdir /usr/local/pcre
[root@linuxprobe src]# tar xzvf pcre-8.35.tar.gz
[root@linuxprobe src]# cd pcre-8.35
[root@linuxprobe pcre-8.35]# ./configure --prefix=/usr/local/pcre
[root@linuxprobe pcre-8.35]# make
[root@linuxprobe pcre-8.35]# make install
安装openssl服务程序(解压与编译过程已省略):
[root@linuxprobe pcre-8.35]# cd /usr/local/src
[root@linuxprobe src]# mkdir /usr/local/openssl
[root@linuxprobe src]# tar xzvf openssl-1.0.1h.tar.gz
[root@linuxprobe src]# cd openssl-1.0.1h
[root@linuxprobe openssl-1.0.1h]# ./config --prefix=/usr/local/openssl
[root@linuxprobe openssl-1.0.1h]# make
[root@linuxprobe openssl-1.0.1h]# make install
把openssl服务程序命令目录添加到环境变量中(永久生效):
[root@linuxprobe pcre-8.35]# vim /etc/profile
//将配置文件最下面的参数追加参数为:
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/openssl/bin
[root@linuxprobe pcre-8.35]# source /etc/profile
安装zlib数据压缩函数库(解压与编译过程已省略):
[root@linuxprobe pcre-8.35]# cd /usr/local/src
[root@linuxprobe src]# mkdir /usr/local/zlib
[root@linuxprobe src]# tar xzvf zlib-1.2.8.tar.gz
[root@linuxprobe src]# cd zlib-1.2.8
[root@linuxprobe zlib-1.2.8]# ./configure --prefix=/usr/local/zlib
[root@linuxprobe zlib-1.2.8]# make
[root@linuxprobe zlib-1.2.8]# make install
创建用于执行nginx服务的用户:
[root@linuxprobe zlib-1.2.8]# cd ..
[root@linuxprobe src]# useradd www -s /sbin/nologin
安装nginx服务程序(openssl,zlib,pcre要写成源码解压路径!!!):
[root@linuxprobe src]# tar xzvf nginx-1.6.0.tar.gz
[root@linuxprobe src]# cd nginx-1.6.0/
[root@linuxprobe nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --without-http_memcached_mole --user=www --group=www --with-http_stub_status_mole --with-http_ssl_mole --with-http_gzip_static_mole --with-openssl=/usr/local/src/openssl-1.0.1h --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.35
[root@linuxprobe nginx-1.6.0]# make
[root@linuxprobe nginx-1.6.0]# make install
创建nginx程序脚本(将下面的参数直接复制进去即可):
[root@linuxprobe nginx-1.6.0]# vim /etc/rc.d/init.d/nginx
#!/bin/bash
# nginx - this script starts and stops the nginx daemon
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
#configtest || return $?
stop
sleep 1
start
}
reload() {
#configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
[root@linuxprobe nginx-1.6.0]# chmod 755 /etc/rc.d/init.d/nginx
重启nginx服务程序并添加到开机启动项:
[root@linuxprobe nginx-1.6.0]# /etc/rc.d/init.d/nginx restart
Restarting nginx (via systemctl): [ OK ]
[root@linuxprobe nginx-1.6.0]# chkconfig nginx on
此时可以通过访问IP来判断nginx服务是否顺利运行
我们一般通过部署Linux+Nginx+MYSQL+PHP这四种开源软件,搭建一个免费、高效、扩展性强、资源消耗低的LNMP动态网站架构。关于这块的安装使用你可以看下http://www.linuxprobe.com/chapter-20.html#2022_Nginx
㈩ linux ubuntu13.10安装nginx1.8.0需要哪些编译环境
sudo//换到rootconfigure //对安装的软件进行配置--prefix=/usr/local/server/nginx //安装目录/usr/local/server/nginx--with-http_stub_status_mole启用 nginx 的 NginxStatus 功能