美文网首页
nginx反向代理的配置样例

nginx反向代理的配置样例

作者: 漫漫江雪 | 来源:发表于2019-05-21 13:46 被阅读0次

nginx-for-windows的基本使用

下载地址: http://nginx.org/en/download.html

使用方式:http://nginx.org/en/docs/windows.html

常用启动命令:

  1. nginx -s stop fast shutdown
  2. nginx -s quit graceful shutdown
  3. nginx -s reload changing configuration, starting new worker processes with a new configuration, graceful shutdown of old worker processes
  4. nginx -s reopen re-opening log files
  5. 查看运行与否:tasklist /fi "imagename eq nginx.exe"
  6. 如果不小心手动运行了 nginx.exe 使用taskkill强制杀死进程
    taskkill /fi "imagename eq nginx.exe" /f

反向代理的配置样例


#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       7777;
        server_name  192.168.4.167;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
        
        location ^~ /api {
            proxy_pass http://192.168.4.189:8085/bigdata-ltyfk;
            proxy_set_header Host $host;
            proxy_set_header X-Real_IP $remote_addr;
            proxy_set_header X-Forwarded-for $remote_addr;
        }
        
        location ^~ /image/upload {
            proxy_pass http://192.168.4.247:4869/upload;
            proxy_set_header Host $host;
            proxy_set_header X-Real_IP $remote_addr;
            proxy_set_header X-Forwarded-for $remote_addr;          
        }
        
        location ^~ /zimg/ {
            proxy_pass http://192.168.4.247:4869/;
            proxy_set_header Host $host;
            proxy_set_header X-Real_IP $remote_addr;
            proxy_set_header X-Forwarded-for $remote_addr;
        }
        
        location ^~ /device/ {
            proxy_pass http://192.168.4.189:7777/;
            proxy_set_header Host $host;
            proxy_set_header X-Real_IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
        }
        
        location ^~ /map {
            proxy_pass http://192.168.0.237:6660/$request_uri;
            proxy_set_header Host $host;
            proxy_set_header X-Real_IP $remote_addr;
            proxy_set_header X-Forwarded-for $remote_addr;
        }
        

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

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


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

}

检测nginx的配置:sudo nginx -c /etc/nginx/nginx.conf
虚拟目录在nginx下的配置
sudo cp -r /home/oeasy/apache-tomcat-8/webapps/highthrow /var/www/
如果要重命名一个文件,可以用mv命令 sudo mv threenone.conf highthrow.conf

server {
    listen    8088;
    server_name  localhost;

    location ^~ /highthrow {
        try_files  $uri   $uri/  /index.html;
        alias /var/www/highthrow;
        index index.html;
    }
    location / {
        try_files $uri $uri/ /highthrow;
    }
}

参考:https://www.cnblogs.com/kevingrace/p/6187482.html

server {
    listen 80;
    server_name localhost;
    location /admin {
        root /home/wordspace/admin;
        index index.html;
        try_files $uri /index.html;
    }
    location / {
        root /home/workspace/vue;
        index index.html;
        try_files $uri /index.html;
    }
}

相关文章

  • Nginx应用场景

    反向代理,负载均衡,动静分离 1.反向代理 修改nginx配置,并重新加载 重新加载nginx配置./nginx ...

  • 01-nginx前端方向代理

    前端反向代理 1.下载nginx 2. 配置nginx.conf反向代理

  • nginx

    nginx的配置、虚拟主机、负载均衡和反向代理一nginx的配置、虚拟主机、负载均衡和反向代理二nginx的配置、...

  • nginx反向代理的配置样例

    nginx-for-windows的基本使用 下载地址: http://nginx.org/en/download...

  • nginx反向代理

    什么是反向代理 如何实现反向代理 准备工作以及安装nginx 配置nginx nginx的初始配置文件去掉注释后的...

  • Nginx中配置https做反向代理 - 知识林

    本文章来自【知识林】 在Centos中的Nginx配置https做反向代理跟配置http做反向代理基本一样,只是多...

  • nginx 配置

    nginx 多个 root页面配置 反向代理

  • 第二课 nginx+tomcat集群

    正向代理,反向代理 配置Nginx 配置文件目录:/usr/local/nginx-1.6.1/conf/ngin...

  • nginx+tomcat集群

    正向代理,反向代理 配置Nginx 配置文件目录:/usr/local/nginx-1.6.1/conf/ngin...

  • nginx+tomcat集群

    正向代理,反向代理 配置Nginx 配置文件目录:/usr/local/nginx-1.6.1/conf/ngin...

网友评论

      本文标题:nginx反向代理的配置样例

      本文链接:https://www.haomeiwen.com/subject/ectjzqtx.html