原文:http://tianyalong.icu/content.html?id=36
nginx目录结构
tyl@iZ8vb4iunamg7wut9ninp3Z:~/nginx$ ls
conf conf.d html log
tyl@iZ8vb4iunamg7wut9ninp3Z:~/nginx$ cd conf
tyl@iZ8vb4iunamg7wut9ninp3Z:~/nginx/conf$ ls
nginx.conf
tyl@iZ8vb4iunamg7wut9ninp3Z:~/nginx/conf$ cd ..
tyl@iZ8vb4iunamg7wut9ninp3Z:~/nginx$ cd conf.d/
tyl@iZ8vb4iunamg7wut9ninp3Z:~/nginx/conf.d$ ls
default.conf
tyl@iZ8vb4iunamg7wut9ninp3Z:~/nginx/conf.d$ cd ..
tyl@iZ8vb4iunamg7wut9ninp3Z:~/nginx$ cd html/
tyl@iZ8vb4iunamg7wut9ninp3Z:~/nginx/html$ ls
ace collect.html discusses.html favicon.ico index.html layui picture7d2da4c5-7830-4d9d-8b24-91be65c83cc7.png write.html
algorithm.html content.html editor.md-master fonts interview.html monitor.html picture83d7ee28-ed31-4d24-a008-5ba95b59c17f.png
code.html css error.html img js notes.html picture8cd66114-c567-488e-ae1a-29c032d89e17.png
tyl@iZ8vb4iunamg7wut9ninp3Z:~/nginx/html$ cd ..
tyl@iZ8vb4iunamg7wut9ninp3Z:~/nginx$ cd log
tyl@iZ8vb4iunamg7wut9ninp3Z:~/nginx/log$ ls
access.log error.log
nginx数据卷
"Mounts": [
{
"Type": "bind",
"Source": "/home/tyl/nginx/log",
"Destination": "/var/log/nginx",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/home/tyl/nginx/conf.d",
"Destination": "/etc/nginx/conf.d",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/home/tyl/nginx/conf/nginx.conf",
"Destination": "/etc/nginx/nginx.conf",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/home/tyl/nginx/html",
"Destination": "/usr/share/nginx/html",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name 8.142.97.150;
#设置logid
if ($time_iso8601 ~ "(\d{4})-(\d{2})-(\d{2})") {
set $my_logid_prefix $1$2$3;
}
if ($msec ~ "(\d{10}).(\d{3})") {
set $my_logid_suffix $1$2;
}
if ($request_id ~ ^([\w][\w][\w][\w][\w][\w][\w][\w][\w])[\w][\w][\w][\w][\w][\w][\w] ) {
set $my_logid_end $1;
}
proxy_set_header X-Log-Id $my_logid_prefix$my_logid_suffix$my_logid_end;
location ~ /v1/websocket {
proxy_pass http://172.26.191.209:7777;
proxy_set_header Upgrade websocket;
proxy_set_header Connection Upgrade;
}
location ~ /v1/ {
#proxy_pass http://172.17.0.1:8888;
proxy_pass http://172.26.191.209:7777;
# add_header Cache-Control no-store;
}
location ~ \.js {
root /usr/share/nginx/html;
add_header Content-Type application/x-javascript;
}
location ~ \.css {
root /usr/share/nginx/html;
add_header Content-Type text/css;
}
location / {
root /usr/share/nginx/html;
index index.html;
# add_header Cache-Control no-store;
}
location ~ /deploy/infos {
proxy_pass http://172.26.191.209:7000;
proxy_set_header Upgrade websocket;
proxy_set_header Connection Upgrade;
}
location ~ /deploy/ {
proxy_pass http://172.26.191.209:7000;
proxy_read_timeout 150;
proxy_send_timeout 150;
}
location ~ /settings/ {
proxy_pass http://172.26.191.209:7001;
}
location ~ /auth/ {
proxy_pass http://172.26.191.209:7002;
}
location ~ /engine/ {
proxy_pass http://172.26.191.209:7003;
}
location ~ /search/ {
proxy_pass http://172.26.191.209:7004;
}
location ~ /argos/ {
proxy_pass http://172.26.191.209:7005;
}
error_page 404 500 502 503 504 /error.html;
}
#include /etc/nginx/conf.d/*.conf;
}
default.conf
default.conf被nginx.conf所引用
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html;
}
# location /v1 { //http://192.168.17.129:9001/edu/会默认打到这个服务器
# proxy_pass http://myserver; //被反向代理的服务器ipport
# proxy_set_header Host $host;
# }
error_page 404 500 502 503 504 /error.html;
#location = /50x.html {
# root /usr/share/nginx/html;
# }
}