nginx 基本使用

96 阅读1分钟
常用命令
  • nginx / start nginx:启动 Nginx
  • nginx -s stop:立刻停止 Nginx 服务
  • nginx -s reload:重新加载配置文件
  • nginx -s quit:平滑停止 Nginx 服务
  • nginx -t:测试配置文件是否正确
  • nginx -v:显示 Nginx 版本信息
  • nginx -V:显示 Nginx 版本信息、编译器和配置参数的信息
基本配置
    conf/nginx.conf
    
    #user  nobody;
    worker_processes  1;

    #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       8207;
	server_name  192.168.2.98;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;


		location  /Api {
			rewrite ^.+Api/?(.*)$ /$1 break;
			include uwsgi_params;
			proxy_pass http://192.168.2.80:9998/;
                        }		
		location /bpi {
			rewrite ^.+bpi/?(.*)$ /$1 break;
			include uwsgi_params;
			proxy_pass http://192.168.2.80:9998/;
                        }
		location / {
			#index index.html index.htm;
			#try_files $uri $uri/ /index.html;
			root  D:/nginx-1.12.2/frontend_project/cangchu/dist;
			try_files $uri $uri/ /index.html;
		}
    }

  

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}