linux下安装nginx及开机自启动

更新时间:2023-06-08 20:21:31 阅读: 评论:0

linux下安装nginx及开机⾃启动⼀、安装nginx
1.从 )
wget nginx/download/nginx-1.5.
2.解压
tar -zxvf nginx-1.5.
3.设置⼀下配置信息,或者不执⾏此步,直接默认配置,与后⾯配置有关
./configure --prefix=/usr/local/nginx
4.make 编译 (make的过程是把各种语⾔写的源码⽂件,变成可执⾏⽂件和各种库⽂件)
make
5.make install 安装 (make install是把这些编译出来的可执⾏⽂件和库⽂件复制到合适的地⽅)
make install
6.启动nginx
/usr/local/nginx/sbin/nginx
7.访问nginx,nginx默认端⼝为80
8.安装过程中可能会遇到的错误
(1)错误为:./configure: error: the HTTP rewrite module requires the PCRE library.
安装pcre-devel解决问题
yum -y install pcre-devel
(2)错误提⽰:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
–without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
–with-http_ssl_module –with-openssl= options.
解决办法:
yum -y install openssl openssl-devel
⼆、nginx开机⾃启动
1.在linux系统的/etc/init.d/⽬录下创建nginx⽂件
vim /etc/init.d/nginx
2.在脚本中添加如下命令:
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:  - 85 15
# description:  NGINX is an HTTP(S) rver, HTTP(S) rever \
#              proxy and IMAP/POP3 proxy rver
depend
# processname: nginx
# config:      /etc/f
# config:      /etc/sysconfig/nginx
# pidfile:    /var/run/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/sbin/nginx"
prog=$(baname $nginx)
NGINX_CONF_FILE="/etc/f"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
ur=`$nginx -V 2>&1 | grep "configure arguments:" | d 's/[^*]*--ur=\([^ ]*\).*/\1/g' -` if [ -z "`grep $ur /etc/passwd`" ]; then
uradd -M -s /bin/nologin $ur
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 $ur $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=$?
echocaroline什么意思
[ $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() {
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
}
ca "$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
3.如果你是⾃定义编译安装的nginx,需要根据您的安装路径修改下⾯这两项配置:
nginx="/usr/local/nginx/sbin/nginx" 修改成nginx执⾏程序的路径。
NGINX_CONF_FILE="/usr/local/nginx/f" 修改成配置⽂件的路径。
4.保存脚本⽂件后设置⽂件的执⾏权限:
chmod a+x /etc/init.d/nginx
5.通过该脚本启动停⽌nginx服务
/etc/init.d/nginx start
/etc/init.d/nginx stop
6.使⽤chkconfig进⾏管理,将nginx服务加⼊chkconfig管理列表
chkconfig --add /etc/init.d/nginx
7.使⽤rvice对nginx进⾏启动,停⽌。重启等操作
rvice nginx start
rvice nginx stop
8.设置终端模式开机启动
chkconfig nginx on
三、发布静态资源
1.确定静态资源存放位置
/home/images
2.修改f配置⽂件
vi /usr/local/nginx/f
3.主要修改如下:
#ur  nobody;
worker_process  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
worker_connections  1024;
}
http {
include      pes;
default_type  application/octet-stream;
#log_format  main  '$remote_addr - $remote_ur [$time_local] "$request" ' #                  '$status $body_bytes_nt "$http_referer" '
#                  '"$http_ur_agent" "$http_x_forwarded_for"';
#                  '"$http_ur_agent" "$http_x_forwarded_for"';
#access_log  logs/access.log  main;
ndfile        on;
#tcp_nopush    on;
#keepalive_timeout  0;
keepalive_timeout  65;
#gzip  on;
rver {
otoscopelisten      80;
rver_name  localhost;lamento
#chart koi8-r;
chart utf-8;
#access_log  logs/host.access.log  main;
location ~ .*\.(gif|jpg|jpeg|png)$ {
expires 24h;
root /home/images/;#指定图⽚存放路径
access_log /home/softs/nginx-1.5.9/logs/images.log;#⽇志存放路径        proxy_store on;
proxy_store_access ur:rw group:rw all:rw;
proxy_temp_path        /home/images/;#图⽚访问路径
proxy_redirect          off;
proxy_t_header        Host 127.0.0.1;
client_max_body_size    10m;
client_body_buffer_size 1280k;
proxy_connect_timeout  900;
proxy_nd_timeout      900;
proxy_read_timeout      900;
proxy_buffer_size      40k;
proxy_buffers          40 320k;
proxy_busy_buffers_size 640k;
proxy_temp_file_write_size 640k;
if ( !-e $request_filename)
{
proxy_pass  127.0.0.1;#默认80端⼝
begin的现在分词
}
}
location / {
root  /home/html; #html访问路径
index  index.html index.htm;
}
#error_page  404              /404.html;
# redirect rver error pages to the static page /50x.html
#
error_page  500 502 503 504  /50x.html;
location = /50x.html {
root  html;
英孚价格}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass  127.0.0.1;
#}
# pass the PHP scripts to FastCGI rver listening on 127.0.0.1:9000

本文发布于:2023-06-08 20:21:31,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/905302.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:安装   路径   启动   配置   设置   存放   开机
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图