当前位置:首页 » 网页前端 » nginx脚本安装图
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

nginx脚本安装图

发布时间: 2022-08-15 23:49:44

A. 安装nginx后,怎么安装/升级到tengine

/*
************************************
**Nginx平滑升级Tengine
************************************
*/
SSH登陆,执行如下的代码
wget -c http://tengine.taobao.org/download/tengine-1.5.1.tar.gz //下载Tengine1.5.1版本

tar zxvf tengine-1.5.1.tar.gz //解压到当前目录

cd tengine-1.5.1 //进入到目录

./configure //执行安装脚本

make //编译安装

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old //备份nginx的配置文件,路径参考你自己的

cp -r objs/nginx /usr/local/nginx/sbin/nginx //复制Tengine文件到nginx下

vi /usr/local/nginx/conf/nginx.conf //编辑nginx.conf,删除如下代码
location /status {
stub_status on;
access_log off;
}

kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
//结束nginx进程

/usr/local/nginx/sbin/nginx -v //查看nginx版本号
返回带有Tengine版本号等信息则升级成功!

/*
************************************
**卸载Tengine,换回Nginx
************************************
*/
rm -rf /usr/local/nginx/sbin/nginx //删除Tengine配置文件

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old //恢复备份的nginx配置文件,路径参考你自己的

/etc/init.d/nginx restart //重启nginx

/usr/local/nginx/sbin/nginx -v //查看nginx版本号
返回带有Nginx版本号则卸载成功

B. nginx编译安装服务启动脚本在哪

在你编译是 --prefix=指定的目录下有一个bin目录,里面有一个nginx启动脚本,如果没有指定,默认在/usr/local/nginx下,即/usr/local/nginx/sbin/nginx

C. Nginx模块怎么调试

(1)修改nginx源代码目录下子目录/auto/cc中的conf文件,将ngx_compile_opt="-c"改为ngx_compile_opt="-c -g"
(2)在编译的时候加上debug选项,nginx的安装脚本如下:
./configure --user=www --group=www --prefix=/export/lx/servers/nginx-debug --add-mole=../ngx_cache_purge-1.2 --with-debug --with-pcre --with-http_sub_mole --with-http_stub_status_mole --with-http_ssl_mole
make -j 18&& make -j 18 install
(3)修改安装完毕之后生成的nginx配置文件:nginx.conf,加入
error_log /export/lx/servers/nginx_debug/logs/error.log debug;配置项
如果是做模块开发,则需要将nginx设置为单进程模式才可以调试开发的模块中的代码
加入如下几句配置项:
worker_processes 1;
master_process off; # 单进程模式
daemon off;

D. 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

E. Nginx怎么安装配置

1、在线安装 Ubuntu版的 sudo apt-get install nginx;CentOS 版 sudo yum install nginx;
2、源码安装 下载地址:http://nginx.org/download/
所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available下
启动程序文件在/usr/sbin/nginx
日志放在了/var/log/nginx中,分别是access.log和error.log
并已经在/etc/init.d/下创建了启动脚本nginx
默认的虚拟主机的目录设置在了/usr/share/nginx/www
在线安装的启动过程$sudo /etc/init.d/nginx start

F. 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 #显示启动失败的服务

G. ubuntu怎么安装nginx+mysql+php

1、更新 1 sudo apt-get update 2、安装nginx 1 sudo apt-get intsall nginx Ubuntu安装之后的文件结构大致为: * 所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available下 *程序文件在/usr/sbin/nginx * 日志放在了/var/log/nginx中 *并已经在/etc/init.d/下创建了启动脚本nginx * 默认的虚拟主机的目录设置在了/var/www/nginx-default 下面可以启动nginx来看看效果(请确保80端口没有其他服务在使用): 1 sudo /etc/init.d/nginx start #或者简单的 1 service nginx start 然后打开浏览器,查看localhost/ 看看是否看到了”Welcome to nginx!” 如果看到了,说明安装成功. 当然,基本上,这块儿都不会出问题. 如果运行不成功,可以先 1 sudo killall apache2 杀掉apache进程 3、安装php sudo apt-get install php5 php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-sqlite php5-xsl 4、安装spawn-fcgi 为什么要安装spawn-fcgi呢,它用来控制php-cgi进程,以防止进程崩溃或是单进程的效率太低. 网上很多人都说要使用spawn-fcgi必须得安装lighttpd,实际上不必要,可以直接安装spawn-fcgi 运行: 1 sudo apt-get install spawn-fcgi 5、配置 接下来就是最让人头疼的配置. 配置Nginx和spawn-fcgi配合运行 (1).在/etc/nginx/fastcgi_params 文件最后,加入一行,可以用 1 sudo vi /etc/nginx/fastcgi_params 加入此行: 1 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; (2).另外需要在PHP-CGI的配置文件(Ubuntu 上此配置文件位于/etc/php5/cgi/php.ini)中,找到cgi.fix_pathinfo选项,修改为: 1 cgi.fix_pathinfo=1; 这样php-cgi方能正常使用SCRIPT_FILENAME这个变量. (3).打开/etc/nginx/sites-available/default文件在 1 2 3 server { listen 80; server_name localhost; 下面添加web根目录的绝对地址,这里是使用的是nginx的默认地址 1 root /var/www/nginx-default 即root和server_name同级这段即相当于apache的默认目录 如果没有这个的话,容易在执行php 文件的时候,会提示”No input file specified”. 我就曾在此绕了好大个圈子才发现问题.然后修改 1 2 3 4 5 6 #location ~ .php$ { #fastcgi_pass 127.0.0.1:9000; #fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; #includefastcgi_params; #} 修改成 1 2 3 4 location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name; include /etc/nginx/fastcgi_params; #包含fastcgi的参数文件地址 6、开始fast_cgi进程 1、sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid 7、设置开机启动fastcgi进程并启动 1 sudo vi /etc/rc.local 添加下一行 1 /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid 如果打开php文件出现:No input file specified请检查php.ini的配置中 1 cgi.fix_pathinfo=1 1 doc_root= 还有,每个虚机要根据自己不同的虚机设置不同的目录,要保证这个路径正确. 检查/etc/nginx/sites-available下的配置文件中,server内包含 root 及地址 而非location内的root 启动 1 fast-cgisudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid 参数含义如下 * -f 指定调用FastCGI的进程的执行程序位置,根据系统上所装的PHP的情况具体设置 * -a 绑定到地址addr * -p 绑定到端口port * -s 绑定到unix socket的路径path * -C 指定产生的FastCGI的进程数,默认为5(仅用于PHP) * -P指定产生的进程的PID文件路径 * -u和-g FastCGI使用什么身份(-u 用户 -g 用户组)运行,Ubuntu下可以使用www-data,其他的根据情况配置,如nobody、apache等现在可以在web根目录下放个探针或php文件测试一下了 8、安装mysql 1 sudo apt-get install mysql-server mysql-client 中间会提示输入Root用户密码,依次输入即可. 启动MySQL 1 sudo /etc/init.d/mysql start 测试mysql服务是否正常: 运行 1 mysql -uroot -p 输入mysql密码 1 show databases; 如果看到下面的内容 Database information_schema mysql 则mysql已正确安装了. 至此,ubuntu下的nginx+php+mysql就安装完成了.