Nginx是开源、高性能、高可靠的 Web 和反向代理服务器,而且支持热部署,可以做到 7 * 24 小时不间断运行,即使运行几个月也不需要重新启动,还能在不间断服务的情况下对软件版本进行热更新。性能是 Nginx 最重要的考量,其占用内存少、并发能力强、能支持高达 5w 个并发连接数,最重要的是, Nginx 是免费的并可以商业化,配置使用也比较简单。

为了方便大家的使用,此篇文章带大家一起看一下我们的常用命令与在用的配置。

常用命令

1、cd /www/wwwroot/runtime/source-vue(切换到jar包目录)

2、关闭应用

ps -aux | grep java (查看在运行的PID)

kill -9 PID (停止运行)

3、启动应用

nohup java -jar source-admin.jar >/usr/sourcebyte/temp.txt & (启动应用并输出日志到临时文件)

Nginx配置


server
{
    listen 80;
	listen 443 ssl http2;
    server_name sourcebyte.vip www.sourcebyte.vip;
    include       mime.types;
    default_type  application/octet-stream;
    proxy_intercept_errors on;
    sendfile        on;
    keepalive_timeout  65;
    # gzip config
    gzip on;
    gzip_min_length 1k;
    gzip_comp_level 9;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";
    client_max_body_size 1024m;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #HTTP_TO_HTTPS_START
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }
    #HTTP_TO_HTTPS_END
    ssl_certificate    /www/server/panel/vhost/cert/sourcebyte.vip/fullchain.pem;
    ssl_certificate_key    /www/server/panel/vhost/cert/sourcebyte.vip/privkey.pem;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    add_header Strict-Transport-Security "max-age=31536000";
    error_page 497  https://$host$request_uri;
		#SSL-END

    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END

    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/sourcebyte.vip.conf;
    #REWRITE-END
    
    access_log  /www/wwwlogs/sourcebyte.vip.log;
    error_log  /www/wwwlogs/sourcebyte.vip.error.log;
    
    location / {				
			if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
				root  /www/wwwroot/sourcebyte.vip/html/site/mobile/h5;
			}
			root   /www/wwwroot/sourcebyte.vip/html/site/dist/;
			index  index.html index.html;
			try_files $uri $uri/ /index.html; 
    }	
    
    location /h5 {
		alias  /www/wwwroot/sourcebyte.vip/html/site/mobile/h5/;
		index  index.html index.html;
		try_files $uri $uri/ /index.html; 
	}
		
	location /article/ {
		proxy_pass https://sourcebyte.vip/h5/pages/article/article; # 转发到手机文章地址
	}
	#接口映射	
	location /api/ {
		 proxy_pass http://localhost:9001/api/;  # 转发地址
	}
	#app common 映射	
	location /common/ {
		  proxy_pass http://localhost:9001/common/;  # 转发地址
	}
	#富文本地址资源映射
	location /web-api/ {	
  		proxy_set_header Host $http_host;
  		proxy_set_header X-Real-IP $remote_addr;
  		proxy_set_header REMOTE-HOST $remote_addr;
  		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  		#websocket
  		proxy_set_header Upgrade $http_upgrade;             
        proxy_set_header Connection "upgrade";
  		proxy_pass http://localhost:9001/;
  	}
  	
  	location /profile {
    	add_header Access-Control-Allow-Origin *;
    	add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
    	add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
    	if ($request_method = 'OPTIONS') {
    		return 204;
    	}	
    	alias  /www/wwwroot/static/uploadPath/;
    	index  index.html index.html;
    }
}