全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 3193|回复: 11

【已经解决,配置大家可以参考下】nginx配置

[复制链接]
发表于 2018-5-27 18:26:08 | 显示全部楼层 |阅读模式
本帖最后由 akige 于 2018-5-27 20:19 编辑

最近忙。后来没去弄这个了。
还是这个帖子。http://www.hostloc.com/thread-446933-3-1.html

大佬您把测试好的配置文件发我就行。你那边建个index.html测试下就行。

请看下上面帖子的需求。 配置文件最好基于军哥的lnmp来改。



这是我的一个配置。老是有问题。


---------------------------------------
追加: 这是我测试后的一个比较满意。容易懂的配置。希望大家能少走弯路。供参考。我用的是301.没用rewrite。



  1. server {
  2.     listen 80;
  3.     server_name xxx.com www.xxx.com;
  4.     return 301 https://www.xxx.com$request_uri;
  5.         #rewrite ^(.*)$ https://www.xxx.com$1 permanent;
  6. }

  7. server {
  8.         listen 443 ssl http2;
  9.         ssl_certificate /etc/letsencrypt/live/xxx.com/fullchain.pem;
  10.     ssl_certificate_key /etc/letsencrypt/live/xxx.com/privkey.pem;
  11.     server_name xxx.com;
  12.     return 301 https://www.xxx.com$request_uri;
  13.         #rewrite ^(.*)$ https://www.xxx.com$1 permanent;
  14. }



  15. server
  16.     {
  17.         listen 443 ssl http2;
  18.         #listen [::]:443 ssl http2;
  19.         server_name www.xxx.com ;
  20.         index index.html index.htm index.php default.html default.htm default.php;
  21.         root  /home/wwwroot/www.xxx.com;
  22.         ssl on;
  23.         ssl_certificate /etc/letsencrypt/live/www.xxx.com/fullchain.pem;
  24.         ssl_certificate_key /etc/letsencrypt/live/www.xxx.com/privkey.pem;
  25.         ssl_session_timeout 5m;
  26.         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  27.         ssl_prefer_server_ciphers on;
  28.         ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
  29.         ssl_session_cache builtin:1000 shared:SSL:10m;
  30.         # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
  31.         ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

  32.        
  33.         include other.conf;
  34.         #error_page   404   /404.html;

  35.         # Deny access to PHP files in specific directory
  36.         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

  37.         include enable-php.conf;
  38.                
  39.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  40.         {
  41.             expires      30d;
  42.         }

  43.         location ~ .*\.(js|css)?$
  44.         {
  45.             expires      12h;
  46.         }

  47.         location ~ /.well-known {
  48.             allow all;
  49.         }

  50.         location ~ /\.
  51.         {
  52.             deny all;
  53.         }

  54.         access_log  /home/wwwlogs/www.xxx.com.log;
  55.     }


复制代码


发表于 2018-5-27 18:31:36 | 显示全部楼层
宝塔默认的http跳https规则直接拿来用不行吗?
发表于 2018-5-27 18:34:49 | 显示全部楼层
帮你顶一下,希望大佬帮你
发表于 2018-5-27 18:37:47 | 显示全部楼层
不带www的 dns那里设置301 nginx这里就做个跳https不就好了
发表于 2018-5-27 18:37:58 | 显示全部楼层
server {
    listen 80;
    server_name xxx.com www.xxx.com;
    return 301 https://www.xxx.com$request_uri;
}
server {
    listen 443 ssl;
    ssl_certificate  /home/ssl/www.xxx.com/www.xxx.com.crt;
    ssl_certificate_key  /home/ssl/www.xxx.com/www.xxx.com.key;
    server_name xxx.com;
    return 301 https://www.xxx.com$request_uri;
}
server
    {
listen 443 ssl http2;
ssl on;
ssl_certificate /home/ssl/www.xxx.com/www.xxx.com.crt;
ssl_certificate_key /home/ssl/www.xxx.com/www.xxx.com.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict–Transport–Security “max-age=31536000”;
        #listen [::]:80;
        server_name www.xxx.com;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/www.xxx.com;
发表于 2018-5-27 18:44:40 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2018-5-27 19:35:05 | 显示全部楼层
server
    {
        listen 80;
        listen 443 ssl;
         ssl_certificate /etc/letsencrypt/live/www.xxx.com/fullchain.pem;
         ssl_certificate_key /etc/letsencrypt/live/www.xxx.com/privkey.pem;#证书路径自己改
                server_name xxx.com ;
                return 301 http://www.xxx.com$request_uri;
    }

server
    {
        listen 80;
        listen 443 ssl http2;
        server_name www.xxx.com ;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/www.xxx.com;
      
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }

        ssl on;
        ssl_certificate /etc/letsencrypt/live/www.xxx.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/www.xxx.com/privkey.pem;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
        ssl_session_cache builtin:1000 shared:SSL:10m;
        # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
        ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;


        include other.conf;
        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;
               
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/www.xxx.com.log;
    }
发表于 2018-5-27 19:36:06 | 显示全部楼层
直接上宝塔不好吗??
 楼主| 发表于 2018-5-27 19:43:56 | 显示全部楼层

www.xxx.com是不会跳的。 你这个。我已经修改。请参考以下我的。谢谢回复!
发表于 2018-5-27 19:44:51 | 显示全部楼层
踏马在逗我?
return 301 和 rewrite 不都是 301 ?

(虽然 rewrite 有 4 种 flag
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-4-20 02:16 , Processed in 0.062809 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表