Nginx 记录
Ehoac Lv3

install

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sudo wget http://nginx.org/download/nginx-1.16.1.tar.gz

sudo tar -zxvf nginx-1.16.1.tar.gz

sudo apt install build-essential libtool libpcre3 libpcre3-dev openssl libssl-dev zlib1g-dev

cd nginx-1.16.1

sudo git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git

sudo ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_stub_status_module --with-threads --with-file-aio --with-mail --with-mail_ssl_module --with-http_sub_module --add-module=ngx_http_substitutions_filter_module

sudo make

sudo make install

info

1
2
3
4
5
6
7
8
9
10
11
12
13
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#user  nobody;
worker_processes 4;

#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 mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 443 ssl;
#填写绑定证书的域名
server_name ehoac.cn;
#网站主页路径。此路径仅供参考,具体请您按照实际目录操作。
root /home/ehoac/deploy/ehblog/public;
index index.html index.htm;
#证书文件名称
ssl_certificate 1_ehoac.cn_bundle.crt;
#私钥文件名称
ssl_certificate_key 2_ehoac.cn.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location /wechat/ {
proxy_pass http://127.0.0.1:8080/web;
proxy_redirect off;
# 后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80;
#填写绑定证书的域名
server_name www.example.com;
#把http的域名请求转成https
return 301 https://$host$request_uri;
}

}

path

1
/usr/local/webserver/nginx

stop

1
sudo pkill -9 nginx

check configure

1
sudo /usr/local/webserver/nginx -t

start

1
sudo /usr/local/webserver/nginx/sbin/nginx -c /usr/local/webserver/nginx/conf/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh

### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO

NAME=nginx
DAEMON=/usr/local/webserver/nginx/sbin/nginx
DAEMON_OPTS="-c /usr/local/webserver/nginx/conf/nginx.conf"
PIDFILE=/var/run/nginx.pid

[ -x "$DAEMON" ] || exit 0

case "$1" in
start)
if [ -f $PIDFILE ]; then
echo "$NAME already running..."
echo -e "\033[1;35mStart Fail\033[0m"
else
echo "Starting $NAME..."
start-stop-daemon -S -p $PIDFILE -m -b -o -q -x $DAEMON -- $DAEMON_OPTS || return 2
echo -e "\033[1;32mStart Success\033[0m"
fi
;;
stop)
echo "Stoping $NAME..."
start-stop-daemon -K -p $PIDFILE -s TERM -o -q || return 2
rm -rf $PIDFILE
echo -e "\033[1;32mStop Success\033[0m"
;;
restart)
$0 stop && sleep 2 && $0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0

 评论