美文网首页
常用的nginx server配置

常用的nginx server配置

作者: 火柴__ | 来源:发表于2018-08-24 15:39 被阅读0次

    常用文件服务器配置

    server {
            listen 80;
            server_name img.coder-hc.com;
            root   /mnt/nfs_root/;
            location / {
                    index  index.html;
            }
    }
    

    普通的反向代理配置

    server {
            listen       80;
            server_name  admin.coder-hc.com;
    
            location / {
                    proxy_pass        http://localhost:8001;
                    proxy_set_header   Host             $host;
                    proxy_set_header   X-Real-IP        $remote_addr;
                    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            }
    }
    

    带ssl证书的反向代理配置

    server {
            listen 443 ssl;
            server_name wx.coder-hc.com;
    
            ssl on;
            ssl_certificate      /etc/nginx/certificate/Nginx/wx.coder-hc.com_ssl.crt;
            ssl_certificate_key  /etc/nginx/certificate/Nginx/wx.coder-hc.com_ssl.key;
    
            ssl_session_timeout 5m;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!aNULL:!eNULL;
            ssl_prefer_server_ciphers on;
    
    
            location / {
                    proxy_pass        http://localhost:8003;
                    proxy_set_header   Host             $host;
                    proxy_set_header   X-Real-IP        $remote_addr;
                    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            }
    }
    

    强制跳转到https访问的配置

    server {
            listen 80;
            server_name md.coder-hc.com;
            return 301 https://$server_name$request_uri;
    }
    

    将url中包含/api/的请求做反向代理

    server {
            listen       80;
            server_name  www.coder-hc.com;
            root         /data/awhapp;
    
            location /api/ {
                    proxy_pass         http://localhost:8001/api/;
                    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;
                location = /40x.html {
            }
    
            error_page 500 502 503 504 /50x.html;
                location = /50x.html {
            }
    }
    

    相关文章

      网友评论

          本文标题:常用的nginx server配置

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