Nginx配置完整示例

2021-01-06  乐帮网

nginx

生产服务器上的配置示例如下:

主要实现了多个站点的反向代理,支持https证书站点,支持默认http转跳到https站点,支持站点内容压缩,支持静态图片红缓存设置,小小的示例五脏俱全够用了。

server {
    listen 80;
    server_name lebang2020.cn www.lebang2020.cn coffee.lebang2020.cn;
    return 301 https://$http_host$request_uri;
}
server{
    listen 443 ssl;
    server_name lebang2020.cn www.lebang2020.cn;
    ssl_certificate /etc/nginx/ssl.conf/lebang2020.cn.pem;
    ssl_certificate_key /etc/nginx/ssl.conf/lebang2020.cn.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    #gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary off;
    gzip_disable "MSIE [1-6]\.";
        location / {
            proxy_pass http://localhost:8003;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection keep-alive;
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
       }
       location /admin/ {
                proxy_pass http://localhost:8002/admin/;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection keep-alive;
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }
        location /res/images/ {
                root /home/wwwroot/;
                 expires 2h;
        }
}

server{
    listen 443 ssl;
    server_name coffee.lebang2020.cn;
    ssl_certificate /etc/nginx/ssl.conf/coffee.lebang2020.cn.pem;
    ssl_certificate_key /etc/nginx/ssl.conf/coffee.lebang2020.cn.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    #gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary off;
    gzip_disable "MSIE [1-6]\.";
       location / {
                proxy_pass http://localhost:8103;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection keep-alive;
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
       }
}

以上便是我珍藏的示例,如果你有更好的建议请在公众号留言,一起学习一起进步。

原创作品,禁止转载!

Nginx学习目录参考这里: Nginx证书的配置

相关文章:

Nginx中$host $http_host和$proxy_host区别

Nginx 配置http强制跳转https

Nginx 反向代理设置 AspNetCore 站点的压缩

您与此网站之间建立的连接并非完全安全(Nginx)

 

公众号二维码

关注我的微信公众号
在公众号里留言交流
投稿邮箱:1052839972@qq.com

庭院深深深几许?杨柳堆烟,帘幕无重数。
玉勒雕鞍游冶处,楼高不见章台路。
雨横风狂三月暮。门掩黄昏,无计留春住。
泪眼问花花不语,乱红飞过秋千去。

欧阳修

付款二维码

如果感觉对您有帮助
欢迎向作者提供捐赠
这将是创作的最大动力