nginx命令

nginx -t #测试nginx配置文件
nginx -s reload #重载nginx服务
nginx -s stop #停止nginx服务
nginx -v #查看版本信息
nginx -V #查看版本信息和编译信息
sudo nginx            # start
sudo nginx -s stop    # stop
sudo nginx -s reload  # restart
sudo systemctl reload nginx

代理http

server {
        listen 80;
        server_name .domain.tld;
        root /var/www/cms;  # Directory root of your CMS.
        index index.php index.html index.htm;

        location / {
                try_files $uri $uri/ /index.php?page=$request_uri;
        }

        location ~ \.php$ {
                include fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
}

REST

try_files $uri $uri/ /index.php$is_args$args;
# Settings for a TLS enabled server.

    server {
        listen       443 ssl http2 default_server;
        server_name  berton.site;
        root         /usr/share/nginx/html;

        ssl_certificate "/etc/nginx/ssl/fullchain.cer";
        ssl_certificate_key "/etc/nginx/ssl/berton.site.key";
		ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

        # Load configuration files for the default server block.
        #include /etc/nginx/default.d/*.conf;

        location /admin {
  	     	proxy_redirect off;
  	     	proxy_pass http://127.0.0.1:1081;
	     	proxy_http_version 1.1;
	     	proxy_set_header Upgrade $http_upgrade;
	     	proxy_set_header Connection "upgrade";
  	     	proxy_set_header Host $http_host;

        	# Show realip in v2ray access.log
        	proxy_set_header X-Real-IP $remote_addr;
        	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

中转

events {
        worker_connections 768;
        # multi_accept on;
}

stream{
    upstream group {
        server berton.site:443;     # ip:port
    }

    server {
        listen 0.0.0.0:80;
        listen 80 udp;
        proxy_pass group;
        proxy_timeout 10m;
        proxy_connect_timeout 5000ms;
    }
}

反向代理

server {

    # 主平台遥感
    location ^~ /geoserver/ {
       proxy_pass http://172.21.94.187:6079;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

# jupyter notebook 代理
upstream notebook {
    server localhost:8888;
}
server{
    listen 80;
    server_name xyz.abc.com;
    location / {
        proxy_pass            http://notebook;
        proxy_set_header      Host $host;
    }

    location ~ /api/kernels/ {
        proxy_pass            http://notebook;
        proxy_set_header      Host $host;
        # websocket support
        proxy_http_version    1.1;
        proxy_set_header      Upgrade "websocket";
        proxy_set_header      Connection "Upgrade";
        proxy_read_timeout    86400;
    }
    location ~ /terminals/ {
        proxy_pass            http://notebook;
        proxy_set_header      Host $host;
        # websocket support
        proxy_http_version    1.1;
        proxy_set_header      Upgrade "websocket";
        proxy_set_header      Connection "Upgrade";
        proxy_read_timeout    86400;
    }

    location ^~ /terminals/ {
        proxy_pass            http://notebook;
        proxy_set_header      Host $host;
        # websocket support
        proxy_http_version    1.1;
        proxy_set_header      Upgrade "websocket";
        proxy_set_header      Connection "Upgrade";
        proxy_read_timeout    86400;
    }
}