当前位置:首页 » 编程软件 » 编译安装nginx

编译安装nginx

发布时间: 2022-01-15 17:23:28

‘壹’ 没有编译环境怎么安装nginx

要编译安装Nginx,首先我们要安装依赖...
1

准备工作完成后就是下载编译安装Nginx...
2

等编译安装完成后在 /usr/local 下就会...
3

由于脚本是我自己写的,

‘贰’ 求大神指导Centos7 源码编译安装Nginx+php 配置动静分离

这个是我的服务的实际 将配置Nginx实现动静分离,对php页面的请求转发给LAMP处理,而静态页面交给Nginx,以实现动静分离。客户请求静态数据给Nginx,Nginx直接应答客户端,当请求动态数据到Nginx时,Nginx让客户端去找LAMP,通过代理的方式,LAMP就和客户端连接了。分别配置动态分离和静态分离

(1)架设并调试后端LAMP架构,指定的域名,IP地址为xxxx,创建动态页面test.php。

(2)配置Nginx(xxxx)处理动态页面请求,并把域名改为 chaodiquan.com 在server{};段中加入以下代码,检测语法后,重启Nginx

(3)客户端输入xxxx/test.php 成功后动态分离就实现了,接下来再配置静态分离

(4)配置Nginx处理静态页面请求,在server{};中加入以下代码,检测语法后,重启Nginx

location ~ .*.(gif|jpg|jpeg|bmp|swf)$ { #这段代码意思是任意网址以这5种格式为结尾就到Nginx根目录下的html文件夹寻找资源

root html;
expires 1d; #缓存一天}

(5)在nginx的html目录中,放入图片aa.jpg,然后在apache的动态测试页test.php中添加

<html>
<body>
<img src="aaaa/aa.jpg">
</body>
</html>

(6)客户端输入xxxx/test.php测试,由于test.php是动态页面,因此客户端会找到LAMP架构中的Apache,然后调取图片aa.jpg是静态数据,所以从Nginx提取,最后反馈给客户端。这个是

‘叁’ 如何在linux下编译nginx

安装nginx

1.下载

2.解压

复制代码代码如下:

tar -zxvf nginx-1.7.0.tar.gz

3.编译和安装

执行如下命令:

#cdnginx-1.7.0#./configure--prefix=/usr/local/nginx-1.7.0--with-http_ssl_mole--with-http_spdy_mole--with-http_stub_status_mole--with-pcre
–with-http_stub_status_mole:支持nginx状态查询–with-http_ssl_mole:支持https–with-http_spdy_mole:支持google的spdy,想了解请网络spdy,这个必须有ssl的支持–with-pcre:为了支持rewrite重写功能,必须制定pcre

最后输出如下内容,表示configure OK了。

‘肆’ 编译安装nginx的配置文件的路径在哪

这个版本不同,位置还是不同的。
我的是nginx-1.9.9版本源码安装,配置文件在conf这个目录里面:
/usr/local/nginx/conf/nginx.conf
如果你找不见也可以搜索:
find / | grep nginx.conf

‘伍’ centos7怎么编译安装nginx

安装环境为:最小化安装的centos7,关闭seliunx。
最小化安装centos:
关闭selinux
sed –i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

开始安装nginx1.7.8
创建群组
groupadd www
创建一个用户,不允许登陆和不创主目录
useradd -s /sbin/nologin -g www -M www
#下载最新版nginx
wget -C http://nginx.org/download/nginx-1.7.8.tar.gz
tar zxvf nginx-1.7.8.tar.gz
#编译基本能运行的nginx
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_mole --with-http_ssl_mole --with-http_gzip_static_mole
make
make install

如果有错误提示:
./configure: error: C compiler cc is not found
解决方法:
yum install gcc gcc-c++

如果有错误提示:
./configure: error: the HTTP rewrite mole requires the PCRE library.
You can either disable the mole by using –without-http_rewrite_mole
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.
解决方法:
yum install pcre-devel

如果有错误提示:
./configure: error: SSL moles require the OpenSSL library.
You can either do not enable the moles, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using –with-openssl=<path> option.
解决方法:
yum install openssl-devel

以上错误提示依次解决后:再一次的运行
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_mole --with-http_ssl_mole --with-http_gzip_static_mole
make
meke install

编译参数解释:
#指定运行权限的用户
--user=www
#指定运行的权限用户组
--group=www
#指定安装路径
--prefix=/usr/local/nginx
#支持nginx状态查询
--with-http_stub_status_mole
#开启ssl支持
--with-http_ssl_mole
#开启GZIP功能
--with-http_gzip_static_mole

因此要顺利的通过nginx编译安装必须安装的依赖关系有:
yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel

2、在 centos7 中为nginx的启动、重启、重载配置添加脚本
nginx直接启动的方法:
/usr/local/nginx/sbin/nginx

但是不是很方便,因此使用下面的脚本来控制nginx的启动关闭重载更加合理一些。
编辑文件:vim /usr/lib/systemd/system/nginx.service 添加下面的脚本,注意路径 !
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

systemctl的一些使用方法:
systemctl is-enabled servicename.service #查询服务是否开机启动
systemctl enable xxx.service #开机运行服务
systemctl disable xxx.service #取消开机运行
systemctl start xxx.service #启动服务
systemctl stop xxx.service #停止服务
systemctl restart xxx.service #重启服务
systemctl reload xxx.service #重新加载服务配置文件
systemctl status xxx.service #查询服务运行状态
systemctl --failed #显示启动失败的服务

因此,添加上面脚本后,centos7 中操作nginx的方法有
systemctl is-enabled nginx.service #查询nginx是否开机启动
systemctl enable nginx.service #开机运行nginx
systemctl disable nginx.service #取消开机运行nginx
systemctl start nginx.service #启动nginx
systemctl stop nginx.service #停止nginx
systemctl restart nginx.service #重启nginx
systemctl reload nginx.service #重新加载nginx配置文件
systemctl status nginx.service #查询nginx运行状态
systemctl --failed #显示启动失败的服务

‘陆’ 怎么编译安装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

‘柒’ 源码安装nginx需要安装哪些东西

nginx配置里面配置一个server段,然后把网站的目录,域名,别名等配置好就可以了。想要好管理配置,用include加个文单花厕拘丿饺搽邪敞矛件,里面专门配置server段

‘捌’ 给已经编译安装好的Nginx添加模块,是要重新再编译安装一次吗

编译信息
configure arguments: --user=w /usr/local/nginx --with-pcre=/tmp/pcre-8.30 --with-http_gzip_static_mole

我现在想添加–with-http_stub_status_mole模块,必须要重新编译一次然后make && make install吗?

‘玖’ 编译安装nginx和yum安装nginx有什么区别

如果真的要说区别的话,源码编译安装可以在各个linux系统下使用,而yum安装只能在redhat或centos系统使用,其它系统例如ubuntu,freebsd是不可用的。另外yum安装的nginx版本偏低,而源码包是可以获取官方最新的发行版本的。

热点内容
战地配置有哪些 发布:2024-10-18 16:44:48 浏览:308
中国联通短信提示服务密码未完善是什么意思 发布:2024-10-18 16:42:17 浏览:709
c语言中非 发布:2024-10-18 16:21:20 浏览:143
招编程人员 发布:2024-10-18 16:19:37 浏览:422
什么数据类型存储图片 发布:2024-10-18 16:19:28 浏览:749
电脑维护服务器 发布:2024-10-18 16:18:51 浏览:435
取舍算法 发布:2024-10-18 16:12:36 浏览:249
安卓数据线一般在什么价位 发布:2024-10-18 16:09:25 浏览:732
老式安卓机怎么插卡 发布:2024-10-18 15:52:35 浏览:338
pc搭建nas服务器 发布:2024-10-18 15:51:59 浏览:266