nginx常用指令和配置

1.启动

cd usr/local/nginx/sbin     
./nginx

2.检查配置文件是否正确

nginx -t -c /usr/local/nginx/conf/nginx.conf
或者
cd  /usr/local/nginx/sbin
./nginx -t

3.重启

cd /usr/local/nginx/sbin

./nginx -s reload

4.关闭

方式一:

.nginx -s stop     立刻停止

.nginx -s quit      完整有序停止

方式二:(粗暴停止!!!)

ps -ef|grep nginx

kill -9 进程号

5.参考链接
https://mp.weixin.qq.com/s?__biz=MzU0OTE4MzYzMw==&mid=2247516769&idx=3&sn=2c9b6a79c8bd1476d99057caedb1875d&chksm=fbb10b9fccc682899bc443838d327796d909e217a21ba36d5853a31078e6bf81ccc47fc9bf89&scene=27

6.企业级nginx.conf配置


#user  nobody;
worker_processes  1;
worker_rlimit_nofile 20480;

#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;
}

stream {     
    upstream oracle {   
	    #原oracle地址
        server 192.166.152.200:1521 weight=1 max_fails=2 fail_timeout=30s;   
        server 192.166.152.201:1521 weight=2 max_fails=2 fail_timeout=30s;
    }  
 server {
        #so_keepalive,会话保持,防止查询飘走 
        listen 1521 so_keepalive=on;       
        proxy_pass oracle;
    }
}

http {
    client_max_body_size 100m;
    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;

    upstream forestWeb{
        server 192.158.70.97:9400;
    }
    upstream natural{
        server 192.158.70.97:9500;
    }
    upstream naturalApi{
        server 192.158.70.97:8611;
    } 
    upstream forestApi{
        server 192.158.70.97:8601;
    }
    upstream fileApi{
        server 192.158.70.97:8610;
    }
    upstream filePreview{
        server 192.158.70.97:9002;
    }
    upstream webSocket {
        server 192.158.70.97:8611;
    }
    upstream dzMap{
        server 192.158.70.97:5080;
    }

    upstream dzWMSMap{
        server 192.158.70.97:7777;
    }
 
    
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        
        location /forestWeb{
            proxy_pass http://forestWeb;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location /natural{
            proxy_pass http://natural;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location /dzMap{
            proxy_pass http://dzMap;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        }


        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
         location = /favicon.ico {
            log_not_found off;
            access_log off;
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
	
    }
    
    server {
        listen       9524;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location /forestApi/{
            proxy_pass http://forestApi/;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

       location /forestWeb{
            proxy_pass http://forestWeb;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }  

       location /dzMap/{
            proxy_pass http://dzMap/;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
	location /dzWMSMap/{
            proxy_pass http://dzWMSMap/;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location /bydz/{
            proxy_pass http://192.159.87.149:5050/;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }


    }

    server {
        listen       9525;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location /fileApi/{
            proxy_pass http://fileApi/;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location /filePreview/{
            proxy_pass http://filePreview/;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location /naturalApi/{
            proxy_pass http://naturalApi/;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        
        location /natural{
            proxy_pass http://natural;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location /dzWMSMap/{
            proxy_pass http://dzWMSMap/;
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location /ws/ {
            proxy_buffering off;
            rewrite ^/webSocket/(.*)$ /$1 break;
            proxy_pass http://webSocket/;
            proxy_read_timeout 300s;
            proxy_send_timeout 300s;

            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #升级http1.1到 websocket协议
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection  $connection_upgrade;
        }

    }



    # 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;
    #    }
    #}
    include conf.d.start/*.conf;
}

posted @ 2022-11-02 09:19  木糖醇困了  阅读(357)  评论(0)    收藏  举报