nginx配置
小于 1 分钟
nginx配置
nginx命令行
windows使用
#启动nginx,不要./nginx.exe,这样会无法关闭
start nginx
# 重载nginx
./nginx.exe -s reload
#停止nginx
./nginx.exe -s stop
#!/bin/bash
#nginx执行程序路径需要修改
nginxd=/usr/local/nginx/sbin/nginx
# nginx配置文件路径需要修改
nginx_config=/usr/local/nginx/conf/nginx.conf
# pid 地址需要修改
nginx_pid=/var/local/nginx/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
# pid 地址需要修改
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/local/nginx/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
检测nginx
#!/bin/bash
# 如果进程中没有nginx则将keepalived进程kill掉
A=`ps -C nginx --no-header |wc -l` ## 查看是否有 nginx进程 把值赋给变量A
if [ $A -eq 0 ];then ## 如果没有进程值得为 零
service keepalived stop ## 则结束 keepalived 进程
fi
nginx 配置
user root;
worker_processes auto;
pid /run/nginx.pid;
events {
use epoll;
multi_accept on;
worker_connections 1024;
}
http {
# 必须加这两个,不然 CSS 无法正常加载
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$request_time"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
gzip on;
gzip_buffers 8 16k;
gzip_min_length 512;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_http_version 1.1;
gzip_types text/plain text/css application/javascript application/x-javascript application/json application/xml;
server {
listen 8001;
server_name localhost 127.0.0.1 139.159.190.24 platform.gitnavi.com;
location / {
root /root/.jenkins/workspace/nestle-platform-front-test/dist;
index index.html index.htm;
try_files $uri /index.html;
}
## 二级目录方式,记得 package.json 添加:"homepage": "cdk8s-markdown",
location ^~ /cdk8s-markdown {
root /root/.jenkins/workspace;
index index.html;
try_files $uri /cdk8s-markdown/index.html;
}
location ^~ /platform/ {
proxy_pass http://127.0.0.1:28081;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ .*\.(js|css)?$ {
root /root/.jenkins/workspace/nestle-platform-front-test/dist;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico|woff|woff2|ttf|eot|txt|svg)$ {
root /root/.jenkins/workspace/nestle-platform-front-test/dist;
}
error_page 404 /404.html;
location = /usr/share/nginx/html/40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /usr/share/nginx/html/50x.html {
}
}
server {
listen 8002;
server_name localhost 127.0.0.1 139.159.190.24 store.gitnavi.com;
location / {
root /root/.jenkins/workspace/nestle-store-front-test/dist;
index index.html index.htm;
try_files $uri /index.html;
}
location ^~ /store/ {
proxy_pass http://127.0.0.1:28082;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ .*\.(js|css)?$ {
root /root/.jenkins/workspace/nestle-store-front-test/dist;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico|woff|woff2|ttf|eot|txt|svg)$ {
root /root/.jenkins/workspace/nestle-store-front-test/dist;
}
error_page 404 /404.html;
location = /usr/share/nginx/html/40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /usr/share/nginx/html/50x.html {
}
}
}