1、文件安装目录说明Nginx安装目录为/usr/local/nginx
Nginx主配置文件目录为/usr/local/nginx/conf/nginx.conf
https密钥key存放目录/usr/local/nginx/sslkey/vhost*
网站存放目录/usr/local/nginx/WebServer
各网站主配置文件存放目录/usr/local/nginx/WebServer/vhost*.conf
2、Nginx主配置文件worker_processes1;
events{
worker_connections1024;
}
http{
includemime.types;
default_typeapplication/octet-stream;
sendfileon;
keepalive_timeout65;
#gzipon;
server{
listen80;#业务监听端口
server_namelocalhost;
#charsetkoi8-r;
#access_loglogs/host.access.logmain;
location/{
roothtml;
indexindex.htmlindex.htm;
}
}
include/usr/local/nginx/WebServer/*.conf;#外链加载的主Nginx的配置文件路径,需要指向到各个网站的配置文件上去
}
3、各网站主配置文件的解释server{
listen80;
;#此处为需要重写的URL地址
rewrite^(.*)https://$server_name$1permanent;
}#以上配置文件的意思为重写服务器的http80端口至https443端口
server{
listen443;
;#此处为https的URL地址
indexindex.html;
root/usr/local/nginx/WebServer/vhostA;#此处为web网站的访问目录,主页路径
ssl_certificate/usr/local/nginx/sslkey/vhostA/full_chain.pem;#此处为配置的https证书路径
ssl_certificate_key/usr/local/nginx/sslkey/vhostA/private.key;#此处为配置的https证书路径
ssl_session_cacheshared:SSL:1m;
ssl_session_timeout5m;
server_tokensoff;
fastcgi_paramHTTPSon;
fastcgi_paramHTTP_SCHEMEhttps;
access_log/usr/local/nginx/logs/httpsaccess.log;
}
4、配置nginx脚本#!/bin/bash
#description:NgnixService
#chkconfig:23458877
#帮助函数
Usage(){
echo$"Usage:$0{start|stop|restart}"
}
#启动函数
start(){
pid_file="/usr/local/nginx/logs/nginx.pid"
if[-f$pid_file];then
echo"NgnixAlreadyRunning,DoNotRunAgain.。"
exit1
else
echo"NgnixServiceIsStartRunning..."
/usr/local/nginx/sbin/./nginx
/usr/local/nginx/sbin/./nginx-sreload
fi
}
#停止函数
stop(){
pid_file="/usr/local/nginx/logs/nginx.pid"
if[-f$pid_file];then
echo"Ngnixcomingtostoprunning"
/usr/local/nginx/sbin/./nginx-sstop
else
echo"Ngnixisnotrunning..."
exit1
fi
}
#选择语句
case$1in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep1
start
;;
*)
Usage
;;
esac
5、将配置文件保存在/etc/init.d/nginx位置即可。之后即可通过下面的命令进行启动服务。chmod+777/etc/init.d/nginx
/etc/init.d/nginxstop/start/restart
标签:web,配置文件,stop,复用,server,nginx,usr,local
来源: /eholog/2685046