跳到主要内容

柏拉文博客

2024年04月27日
柏拉文
越努力,越幸运

一、认识


1.1 Mac

1.2 Linux

Linux 安装在 /usr/local/webserver/nginx 位置, 在配置路径时, 有以下几点认识:

  1. xx/xx = /usr/local/webserver/nginx/xx/xx, 是以 Nginx 为出发点的相对位置

  2. /xx/xx 是绝对路径

1.3 Windows

二、配置


2.1 nginx.conf

user root;
worker_processes 1;

events {
worker_connections 1024;
}

http {
sendfile on;
include mime.types;
keepalive_timeout 65;
default_type application/octet-stream;

server {
listen 80;
#access_log logs/access.log;
#error_log logs/error.log debug;

server_name ~(www\.)?(bolawen\.(com|cn))$;
set $proxyHost1 $1;
set $proxyHost2 $2;
set $proxyHost3 $3;
rewrite ^/(.*) https://$proxyHost2/$1 permanent;

include location_proxy.conf;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}


server {
listen 443 ssl;
server_name bolawen.com;
ssl_certificate cert/bolawen.com_bundle.crt;
ssl_certificate_key cert/bolawen.com.key;
ssl_session_cache shared:SSL:1m;
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;
include location_proxy.conf;
}
}

2.2 location_proxy.conf

location / {
alias /root/bolawen/blog-docusaurus-webpack/build/;
index index.html;
}
location /resource{
alias /root/bolawen/resource;
valid_referers bolawen.com localhost;
if ($invalid_referer) {
return 404;
}
}
location /legacy {
alias /root/bolawen/blog-vuepress-webpack/docs/;
index index.html;
}
location /collect {
alias /root/bolawen/collect/build/;
index index.html;
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^/(collect)/(.+)$ /$1/index.html last;
}
location /server {
rewrite ^/server/(.*) /$1 break;
proxy_pass http://localhost:4000;

}