• linux nginx 安装 与 配置


    1,安装

    下载
    sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    
    
    安装
    sudo yum install -y nginx
    
    查看安装路径
    whereis nginx
    如 nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
    
    
    添加启动服务
    sudo systemctl start nginx.service
    
    设置开机启动
    sudo systemctl enable nginx.service

    2.操作

    指定配置文件启动
    nginx -c /etc/nginx/nginx.conf
    重启 【指定配置文件重启
    /usr/sbin/nginx -s reload -c /etc/nginx/nginx.conf
    查看进程信息
    ps
    -ef | grep nginx
    关闭
    nginx
    -s stop

    3.配置模板

    使用 yum 安装 ,配置文件在  /etc/nginx 里面

    user  nginx;
    worker_processes  2;
    
    #error_log  /var/log/nginx/error.log notice;
    #pid        /var/run/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        sendfile        on;
        tcp_nopush     on;
        #网关连接时间最长1600秒
        keepalive_timeout  3600;
    
          #后台集群地址
    
          upstream eureka {
                 server 127.0.0.1:51;
           }
    
          upstream zuul {
                 server 127.0.0.1:52;
          }
    
    
    
    #    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  /var/log/nginx/access.log  main;
    
        #gzip  on;
    
    #    include /etc/nginx/conf.d/*.conf;
    
    server {
               listen       80;
               server_name  mynginx666;
        #---------------------------------
    
          #上传包的大小
          client_max_body_size     500m;
          # 从建立连接开始到发送完head的时间
                client_header_timeout    10s;
          #发送完head以后到发送完body的时间
                client_body_timeout     10s;
          #和后端建立连接的时间(3次握手)
                proxy_connect_timeout    600s;
                proxy_read_timeout      600s;
                proxy_send_timeout      600s;
    
                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 ^~ /zuul {
                proxy_pass  http://zuul;
    
                 proxy_set_header Host $host;
                 proxy_set_header  X-Real-IP  $remote_addr;
                 proxy_set_header X-Forwarded-For $remote_addr;
                 #proxy_set_header Host $host:$server_port;
                 proxy_set_header X-Forwarded-Proto $scheme;
                 proxy_set_header X-Forwarded-Port $server_port;
    
    
            }
    
                # 访问附件-[之后可以访问图片-其他附件不允许直接暴露]
                location ^~ /attchApi/images/ {
                     alias  /home/syb/file/images/ ;
                   autoindex  on;
                }
    
                #访问vue 静态页面
               location ^~ / {
                # proxy_pass  http://vue/;
                root  /home/syb/project/vue/;
                try_files $uri $uri/ /index.html;
                }
    
                error_page   500 502 503 504  /50x.html;
                location = /50x.html {
                    root   html;
                }
    
      }
    
    
    server {
               listen       443 ssl;
               server_name  api.pinshen.biz;
    
               ssl on;
               #需要在同级文件夹放ssl的证书解压文件
               ssl_certificate      server.pem;
               ssl_certificate_key  server.key;
    
        #---------------------------------
    
          #上传包的大小
          client_max_body_size     500m;
          # 从建立连接开始到发送完head的时间
                client_header_timeout    10s;
          #发送完head以后到发送完body的时间
                client_body_timeout     10s;
          #和后端建立连接的时间(3次握手)
                proxy_connect_timeout    600s;
                proxy_read_timeout      600s;
                proxy_send_timeout      600s;
    
                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 ^~ /zuul {
                proxy_pass  http://zuul;
    
                 proxy_set_header Host $host;
                 proxy_set_header  X-Real-IP  $remote_addr;
                 proxy_set_header X-Forwarded-For $remote_addr;
                 #proxy_set_header Host $host:$server_port;
                 proxy_set_header X-Forwarded-Proto $scheme;
                 proxy_set_header X-Forwarded-Port $server_port;
    
    
            }
    
                # 访问附件-[之后可以访问图片-附件不允许直接暴露]
                location ^~ /attchApi/images/ {
                     alias  /home/syb/file/images/ ;
                 #  root   /home/syb/file/;
                   autoindex  on;
                }
    
                #访问vue 静态页面
               location ^~ / {
                # proxy_pass  http://vue/;
                root  /home/syb/project/vue/;
                try_files $uri $uri/ /index.html;
                }
    
                error_page   500 502 503 504  /50x.html;
                location = /50x.html {
                    root   html;
                }
    
      }
    
    }
    View Code

    顺便把win10的配置也记录下

    #user  nobody;
    worker_processes  2;
    
    #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;
    
        sendfile        on;
        tcp_nopush     on;
    
        #keepalive_timeout  0;
        #网关连接时间最长1600秒
        keepalive_timeout  3600;
    
        #     后台集群地址
    
          upstream eureka {
                  server 127.0.0.1:51;
    #               server 192.168.0.45:8000;
             }
    
             upstream zuul {
                    server 127.0.0.1:52;
                }
            upstream permission {
                    server 127.0.0.1:53;
                }
            upstream weixin {
                    server 127.0.0.1:54;
                }
    
             upstream vue {
                    server 127.0.0.1:59;
                }
    
    
    server {
                   listen       50;
                   server_name  api.cenxi.cn;
    
        #gzip  on;
    
        #---------------------------------
    
            #上传包的大小
            client_max_body_size     500m;
            # 从建立连接开始到发送完head的时间
                client_header_timeout    10s;
            #发送完head以后到发送完body的时间
                client_body_timeout     10s;
            #和后端建立连接的时间(3次握手)
                proxy_connect_timeout    600s;
                proxy_read_timeout      600s;
                proxy_send_timeout      600s;
    
                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 ^~ /wieixin {
                    proxy_pass  http://zuul/wieixin;
                 proxy_set_header Host $host;
                 proxy_set_header  X-Real-IP  $remote_addr;
                 proxy_set_header X-Forwarded-For $remote_addr;
                 #proxy_set_header Host $host:$server_port;
                 proxy_set_header X-Forwarded-Proto $scheme;
                 proxy_set_header X-Forwarded-Port $server_port;
            }
            location ^~ /manage {
                proxy_pass  http://zuul/manage;
                 proxy_set_header Host $host;
                 proxy_set_header  X-Real-IP  $remote_addr;
                 proxy_set_header X-Forwarded-For $remote_addr;
                 #proxy_set_header Host $host:$server_port;
                 proxy_set_header X-Forwarded-Proto $scheme;
                 proxy_set_header X-Forwarded-Port $server_port;
            }
             location ^~ /permission {
                        proxy_pass  http://zuul/permission;
                 proxy_set_header Host $host;
                 proxy_set_header  X-Real-IP  $remote_addr;
                 proxy_set_header X-Forwarded-For $remote_addr;
                 #proxy_set_header Host $host:$server_port;
                 proxy_set_header X-Forwarded-Proto $scheme;
                 proxy_set_header X-Forwarded-Port $server_port;
            }
             location ^~ /weixin {
                        proxy_pass  http://zuul/weixin;
                 proxy_set_header Host $host;
                 proxy_set_header  X-Real-IP  $remote_addr;
                 proxy_set_header X-Forwarded-For $remote_addr;
                 #proxy_set_header Host $host:$server_port;
                 proxy_set_header X-Forwarded-Proto $scheme;
                 proxy_set_header X-Forwarded-Port $server_port;
            }
    
    
            location ^~ /zuul {
                proxy_pass  http://zuul;
    
                 proxy_set_header Host $host;
                 proxy_set_header  X-Real-IP  $remote_addr;
                 proxy_set_header X-Forwarded-For $remote_addr;
                 #proxy_set_header Host $host:$server_port;
                 proxy_set_header X-Forwarded-Proto $scheme;
                 proxy_set_header X-Forwarded-Port $server_port;
    
    
            }
    
            location ^~ /eureka {
                    proxy_pass  http://eureka/;
                }
    
            # 访问附件
            location ^~/attchApi/images/{
                 alias  E:/projectWorkSpace/8-syb-manage/file/images/ ;
            }
    
    
    #    vue前端  ,访问 http://localhost:50/
           location ^~ / {
                   proxy_pass  http://vue/;
               }
    
    #        #访问vue 静态页面
    #       location ^~ / {
    #        # proxy_pass  http://vue/;
    #        root  E:/projectWorkSpace/8-syb-manage/myvue-springcloud-master/vue/;
    #        try_files $uri $uri/ /index.html;
    #         autoindex  on;
    #        }
    
    
                #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;
                }
    }
    
    server {
                   listen       8080;
                   server_name  api.cenxi.cn;
    
        #gzip  on;
    
        #---------------------------------
    
            #上传包的大小
            client_max_body_size     500m;
            # 从建立连接开始到发送完head的时间
                client_header_timeout    10s;
            #发送完head以后到发送完body的时间
                client_body_timeout     10s;
            #和后端建立连接的时间(3次握手)
                proxy_connect_timeout    600s;
                proxy_read_timeout      600s;
                proxy_send_timeout      600s;
    
                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 ^~ /wieixin {
                    proxy_pass  http://zuul/wieixin;
                 proxy_set_header Host $host;
                 proxy_set_header  X-Real-IP  $remote_addr;
                 proxy_set_header X-Forwarded-For $remote_addr;
                 #proxy_set_header Host $host:$server_port;
                 proxy_set_header X-Forwarded-Proto $scheme;
                 proxy_set_header X-Forwarded-Port $server_port;
            }
            location ^~ /manage {
                proxy_pass  http://zuul/manage;
                 proxy_set_header Host $host;
                 proxy_set_header  X-Real-IP  $remote_addr;
                 proxy_set_header X-Forwarded-For $remote_addr;
                 #proxy_set_header Host $host:$server_port;
                 proxy_set_header X-Forwarded-Proto $scheme;
                 proxy_set_header X-Forwarded-Port $server_port;
            }
             location ^~ /permission {
                        proxy_pass  http://zuul/permission;
                 proxy_set_header Host $host;
                 proxy_set_header  X-Real-IP  $remote_addr;
                 proxy_set_header X-Forwarded-For $remote_addr;
                 #proxy_set_header Host $host:$server_port;
                 proxy_set_header X-Forwarded-Proto $scheme;
                 proxy_set_header X-Forwarded-Port $server_port;
            }
             location ^~ /weixin {
                        proxy_pass  http://zuul/weixin;
                 proxy_set_header Host $host;
                 proxy_set_header  X-Real-IP  $remote_addr;
                 proxy_set_header X-Forwarded-For $remote_addr;
                 #proxy_set_header Host $host:$server_port;
                 proxy_set_header X-Forwarded-Proto $scheme;
                 proxy_set_header X-Forwarded-Port $server_port;
            }
    
    
            location ^~ /zuul {
                proxy_pass  http://zuul;
    
                 proxy_set_header Host $host;
                 proxy_set_header  X-Real-IP  $remote_addr;
                 proxy_set_header X-Forwarded-For $remote_addr;
                 #proxy_set_header Host $host:$server_port;
                 proxy_set_header X-Forwarded-Proto $scheme;
                 proxy_set_header X-Forwarded-Port $server_port;
    
    
            }
    
            location ^~ /eureka {
                    proxy_pass  http://eureka/;
                }
    
            # 访问附件
            location ^~/attchApi/images/{
                 alias  E:/projectWorkSpace/8-syb-manage/file/images/ ;
            }
    
    
    # #    vue前端  ,访问 http://localhost:50/
    #        location ^~ / {
    #                proxy_pass  http://vue/;
    #            }
    
           #访问vue 静态页面
          location ^~ / {
           # proxy_pass  http://vue/;
           root  E:/projectWorkSpace/8-syb-manage/myvue-springcloud-master/vue/;
           try_files $uri $uri/ /index.html;
            autoindex  on;
           }
    
    
                #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;
                }
    }
    
    
    
    
    }
    View Code
  • 相关阅读:
    系统设计实现
    反编译
    android layout analyze
    2016.7.20-notes
    如何认识刘昊然?
    leetcode-中等-队列-二叉树的层次遍历
    leetcode-简单-栈-逆波兰表达式
    leetcode-简单-栈-有效的括号
    队列-链式队列
    队列-循环队列-顺序存储
  • 原文地址:https://www.cnblogs.com/c2g5201314/p/15778653.html
Copyright © 2020-2023  润新知