求助 nginx 相关问题! v2er 救救孩子吧!呜呜呜! - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
chenli100681
V2EX    程序员

求助 nginx 相关问题! v2er 救救孩子吧!呜呜呜!

  •  
  •   chenli100681 2023-09-08 16:31:32 +08:00 3421 次点击
    这是一个创建于 766 天前的主题,其中的信息可能已经有所发展或是发生改变。
    叠个甲先:本人非计算机相关专业大学生,根据 R 神 xtls 教程一步步建梯子。重点来了:我是傻逼!我是傻逼!我是傻逼!高贵的 v2er 们帮帮我这个唐氏吧!

    现在到了做伪装网站一步。我先概述一下我的材料准备情况。

    有一个().me 的域名,在 cloudflare 已经添加了一条指向我 vps 的 A 记录解析,ssl 安全选的是 full(strict)模式

    vps 甚至防火墙都关了,端口放行应该没啥问题。

    vps 已经安装 nginx ,vps 非 root 登录,用的是用户名()登录,在/home/()/www/webpage 里面搞了个简单的 index.html,去/etc/nginx/nginx.conf 里面设置的路径也绝对是对的

    但是!

    访问域名只显示那个经典的 welcome to nginx ,而不是我 index.html 里面内容,我怀疑因为这一步出错,导致我后面一步申请 ssl 证书也失败了(我猜是 CA 无法判断我掌控该域名?)

    真给我愁死了,呜呜呜,打个胶先

    ![第一次发帖加图片]( https://imgur.com/a/FMJnadK)

    ![我测,imgur 好像可以几张图片一个链接]( https://imgur.com/a/FMJnadK)
    55 条回复    2023-09-10 20:10:57 +08:00
    OceanBreeze
        1
    OceanBreeze  
       2023-09-08 16:42:51 +08:00
    `nginx -s reload` 了么
    yzding
        2
    yzding  
       2023-09-08 16:43:57 +08:00
    证书申请打开 --debug 看看,是不是 Nginx 占用了端口没启动 acme 验证成功
    clickhouse
        3
    clickhouse  
       2023-09-08 16:46:44 +08:00
    1. 修改完 nginx 配置之后有做 reload 吗?
    2. 是采用访问域名内特定文件的方式验证域名所有权申请 SSL 证书的吗?正常使用验证 DNS TXT 解析的方式是比较多的,建议 OP 详细说一下是什么途径什么方式申请的证书。
    defunct9
        4
    defunct9  
       2023-09-08 16:46:54 +08:00   4
    开 ssh ,让我上去看看
    Asakijz
        5
    Asakijz  
       2023-09-08 16:52:19 +08:00
    开 ssh ,让他上去看看 @defunct9
    chenli100681
        6
    chenli100681  
    OP
       2023-09-08 16:54:40 +08:00
    @OceanBreeze #1 sudo systemctl reload 我都敲烂了,呜呜呜
    chenli100681
        7
    chenli100681  
    OP
       2023-09-08 16:54:58 +08:00
    @defunct9 #4 逆天
    chenli100681
        8
    chenli100681  
    OP
       2023-09-08 16:56:29 +08:00
    @clickhouse #3 reload 过了,然后第二点我先去谷歌一下你说的啥意思(我比较菜)但我用的命令是这个 acme.sh --issue --server letsencrypt --test -d 二级域名.你的域名.com -w /home/vpsadmin/www/webpage --keylength ec-256
    感谢大佬!
    chenli100681
        9
    chenli100681  
    OP
       2023-09-08 16:56:48 +08:00
    @yzding #2 okok ,我去看看去,首先感谢大佬!
    chenli100681
        10
    chenli100681  
    OP
       2023-09-08 16:58:23 +08:00
    @Asakijz #5 我读书少,怎么感觉不太对劲
    mabeple
        11
    mabeple  
       2023-09-08 16:58:49 +08:00
    sadfQED2
        12
    sadfQED2  
       2023-09-08 17:00:35 +08:00 via Android
    nginx 配置内容贴上来,我目测你都没把 web 页面路径指向你写的那个 html
    chenli100681
        13
    chenli100681  
    OP
       2023-09-08 17:06:32 +08:00
    @sadfQED2 #12 我想回复您图片,但 v2 说我是太新的用户不让发。麻烦您看一下我帖子最后一行里面最后一张图片?nginx.conf 里面我路径写了/home/()/web/webpage 了,应该不会错,查了好久,呜呜,感谢!
    NessajCN
        14
    NessajCN  
       2023-09-08 17:08:41 +08:00
    依次打以下几个命令,把结果贴上来
    ls -alF /etc/nginx/sites-enabled
    cat /etc/nginx/sites-available/default
    cat /etc/nginx/nginx.conf

    贴全
    sadfQED2
        15
    sadfQED2  
       2023-09-08 17:13:01 +08:00 via Android
    你这个配置文件不对吧,我感觉你 nginx 加载的不是这个文件,cf 通过 https 请求你服务器的,但是你这个配置文件是 80 端口的
    chenli100681
        16
    chenli100681  
    OP
       2023-09-08 17:13:59 +08:00
    @NessajCN #14 不管怎样,先给您磕一个!
    total 8
    drwxr-xr-x 2 root root 4096 Sep 2 07:32 ./
    drwxr-xr-x 8 root root 4096 Sep 8 07:37 ../
    lrwxrwxrwx 1 root root 34 Sep 2 07:32 default -> /etc/nginx/sites-available/default

    ##
    # You should look at the following URL's in order to grasp a solid understanding
    # of Nginx configuration files in order to fully unleash the power of Nginx.
    # https://www.nginx.com/resources/wiki/start/
    # https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
    # https://wiki.debian.org/Nginx/DirectoryStructure
    #
    # In most cases, administrators will remove this file from sites-enabled/ and
    # leave it as reference inside of sites-available where it will continue to be
    # updated by the nginx packaging team.
    #
    # This file will automatically load configuration files provided by other
    # applications, such as Drupal or Wordpress. These applications will be made
    # available underneath a path with that package name, such as /drupal8.
    #
    # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
    ##

    # Default server configuration
    #
    server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
    }

    # pass PHP scripts to FastCGI server
    #
    #location ~ \.php$ {
    # include snippets/fastcgi-php.conf;
    #
    # # With php-fpm (or other unix sockets):
    # fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    # # With php-cgi (or other tcp sockets):
    # fastcgi_pass 127.0.0.1:9000;
    #}

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


    # Virtual Host configuration for example.com
    #
    # You can move that to a different file under sites-available/ and symlink that
    # to sites-enabled/ to enable it.
    #
    #server {
    # listen 80;
    # listen [::]:80;
    #
    # server_name example.com;
    #
    # root /var/www/example.com;
    # index index.html;
    #
    # location / {
    # try_files $uri $uri/ =404;
    # }
    #}

    user www-data;
    worker_processes auto;
    pid /run/nginx.pid;
    include /etc/nginx/modules-enabled/*.conf;

    events {
    worker_connections 768;
    # multi_accept on;
    }

    http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/Javascript text/xml application/xml application/xml+rss text/Javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    server {
    listen 80;
    server_name shayu100861.me;
    root /home/vpssf/www/webpage;
    index index.html;
    }

    }


    #mail {
    # # See sample authentication script at:
    # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
    #
    # # auth_http localhost/auth.php;
    # # pop3_capabilities "TOP" "USER";
    # # imap_capabilities "IMAP4rev1" "UIDPLUS";
    #
    # server {
    # listen localhost:110;
    # protocol pop3;
    # proxy on;
    # }
    #
    # server {
    # listen localhost:143;
    # protocol imap;
    # proxy on;
    # }
    #}
    sadfQED2
        17
    sadfQED2  
       2023-09-08 17:14:20 +08:00 via Android
    你配置文件里面是不是还有一个监听 443 端口的 server 配置?你要改那个才行
    NessajCN
        18
    NessajCN  
       2023-09-08 17:19:10 +08:00
    @chenli100681
    这样就清楚了
    首先你在/etc/nginx/nginx.conf 里 include /etc/nginx/sites-enabled/*;
    然后你在/etc/nginx/sites-enabled/default 里覆盖了 nginx.conf 里的配置,里面的 root /var/www/html 覆盖了你自己设置的

    所以你的处理方法是
    要么注释掉 include /etc/nginx/sites-enabled/*; 这一行,
    要么把配置写到 /etc/nginx/sites-enabled/default 里
    ljh0585
        19
    ljh0585  
       2023-09-08 17:21:47 +08:00
    检查下是不是端口被占用了
    0m9ionbP8wuvs8S3
        20
    0m9ionbP8wuvs8S3  
       2023-09-08 17:24:28 +08:00
    建议直接买机场就不用这么麻烦了
    jiny2048
        21
    jiny2048  
       2023-09-08 17:32:36 +08:00
    你开了 Cloudflare 的 Full(Strict) 模式,意味着 Cloudflare 和你的服务器之间同样采用 https 连接,也就是说 1. 你需要在 nginx 上配置你的域名监听 443 端口并处理 https 请求 2. 你需要在 Cloudflare 中创建新的 Cloudflare Origin Certificate 并将生成的公私钥存储在服务器上,并在 nginx 配置上指向对应路径。
    这部分配置信息在配置文件中(默认是 sites-enabled/default )中长这样:
    ```
    server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    ssl_certificate /etc/ssl/cert.pem;
    ssl_certificate_key /etc/ssl/key.pem;
    ...
    }
    sunxf
        22
    sunxf  
       2023-09-08 17:32:41 +08:00
    配置里面有域名
    chenli100681
        23
    chenli100681  
    OP
       2023-09-08 17:54:12 +08:00
    @NessajCN @sadfQED2 刚刚回复过于频繁,封了 30min 没法回消息, @sadfQED2 您 15 楼说的问题应该就是 18 楼的问题,感谢,给您二位磕一个,如果不介意,收款码发下,请二位喝个奶茶吧,感谢!
    chenli100681
        24
    chenli100681  
    OP
       2023-09-08 17:54:41 +08:00
    @sunxf #22 域名泄露会有什么问题吗?我读书少
    chenli100681
        25
    chenli100681  
    OP
       2023-09-08 17:55:32 +08:00
    @chenli100681 #23 说错了,应该是楼下 21 楼
    xuxihai
        26
    xuxihai  
       2023-09-08 17:56:25 +08:00
    @chenli100681 你使用的是 cloudflare 的 full(strict)模式,都走的是严格加密模式,不适合使用 http 文件验证, 建议如下:

    1. 仍然想使用文件验证,不要使用 full(strict)模式,换成不加密的或者先跳过 CDN 防护,
    2. 换成使用 dns 验证,走动态添加 txt 记录的方式,下面是在 CF 平台上获取 CF 的 api key 后的使用:

    相关链接: https://github.com/acmesh-official/acme.sh/wiki/How-to-issue-a-cert

    ```sh
    export CF_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
    export CF_Email="[email protected]"
    acme.sh --issue -d example.com --dns dns_cf
    ```
    chenli100681
        27
    chenli100681  
    OP
       2023-09-08 17:58:03 +08:00
    @jiny2048 #21 如果我换成 cloudflare flexible 模式呢?
    NessajCN
        28
    NessajCN  
       2023-09-08 18:01:27 +08:00
    @chenli100681 问题解决了就行
    另外我和 21 楼说的不是一个问题,我只是帮你解决了 nginx 主页指向的问题,https 的部分因为你首先没解决主页指向的话是解决不了的所以我没提。你如果已经可以正确显示主页,那你可以试着再跑一遍 acme 脚本
    chenli100681
        29
    chenli100681  
    OP
       2023-09-08 18:07:18 +08:00
    @NessajCN #28 15 楼是另一个兄弟的回复哈哈,不过我知道大佬您 14 楼的回复是帮我解决 nginx 主页指向的问题,感谢!不过我现在重新域名访问直接 403forbidden 了,我到现在的操作只是根据您的指导像这样注释了# include /etc/nginx/sites-enabled/*;
    xuxihai
        30
    xuxihai  
       2023-09-08 18:07:51 +08:00
    @chenli100681 另外使用 full(strict)模式,也可以直接使用 cloudflare 提供的 ssl 证书, 不用再使用 acme.sh 申请标准证书.

    相关文档链接: https://developers.cloudflare.com/ssl/origin-configuration/origin-ca/
    sunxf
        31
    sunxf  
       2023-09-08 18:10:23 +08:00
    @chenli100681 会有什么问题我说不好,只是注意到前面的图片 你都屏蔽了域名,这里没有,所以提示你一下。
    chenli100681
        32
    chenli100681  
    OP
       2023-09-08 18:12:23 +08:00
    @xuxihai #30 ok 谢谢!我去研究一下
    NessajCN
        33
    NessajCN  
       2023-09-08 18:12:44 +08:00 via Android
    @chenli100681 噢,正常,你看 nginx.conf 顶上有一行 user www-data ,你把 index.html 放到自己的家目录里,www-data 这个系统用户是访问不到的,权限或用户自己调一调,譬如改成你自己用户名
    yaott2020
        34
    yaott2020  
       2023-09-08 18:14:12 +08:00 via Android
    @chenli100681 你需要像 x-ui 这样的面板。。。。
    chenli100681
        35
    chenli100681  
    OP
       2023-09-08 18:14:40 +08:00
    @sunxf #31 哈哈,善意的提醒,之后懒得遮了,希望没事
    chenli100681
        36
    chenli100681  
    OP
       2023-09-08 18:15:53 +08:00
    @yaott2020 #34 我们彩笔是这样的,呜呜呜,但 linux 越是虐我,我越觉得 Linux 高不可测有意思,程序员在我心里地位越发崇高
    urmyfaith
        37
    urmyfaith  
       2023-09-08 18:23:49 +08:00
    怀疑是钓鱼贴
    sunxf
        38
    sunxf  
       2023-09-08 18:27:13 +08:00
    @chenli100681 对了,建议增强一下 ssh 登录的安全性。
    sunxf
        39
    sunxf  
       2023-09-08 18:28:42 +08:00
    增强一下 ssh 登录的安全性:1. 将 ssh 登录的端口改成别的 2. 将登录密码改的复杂一点(包括 root 用户和你常用的用户)
    6bsLo69Qdu3RPY4c
        40
    6bsLo69Qdu3RPY4c  
       2023-09-08 18:36:10 +08:00
    直接 x-ui.能省时间去赚钱
    chenli100681
        41
    chenli100681  
    OP
       2023-09-08 18:55:04 +08:00
    @NessajCN #33 我测,行了,大哥您看怎么方便怎么来,我请一杯奶茶的钱还是有的(又禁止回复 30min,这网站设计是否有点离谱)
    chenli100681
        42
    chenli100681  
    OP
       2023-09-08 18:55:45 +08:00
    @urmyfaith #37 ?给我整不会了
    chenli100681
        43
    chenli100681  
    OP
       2023-09-08 18:56:52 +08:00
    @sunxf #39 哈哈谢谢提醒哈,R 神的教程上来就是让我禁 root 登录,换 ssh 端口,用 rsa 证书登录滴,感谢
    rccoder
        44
    rccoder  
       2023-09-08 19:09:38 +08:00
    你你你你你...用宝塔吧=。=
    chenli100681
        45
    chenli100681  
    OP
       2023-09-08 21:02:02 +08:00
    @rccoder #44 我的 linux
    artieo
        46
    artieo  
       2023-09-09 05:46:43 +08:00
    @jiny2048 SSL/TLS Full(Strict) 模式,cf 开启代理才会生效的
    artieo
        47
    artieo  
       2023-09-09 05:51:48 +08:00
    这么一点都不会为什么不用 x-ui,去 vps 的后台重装系统然后再安装,https://github.com/vaxilu/x-ui,安装命令是`bash <(curl -Ls https://raw.githubusercontent.com/vaxilu/x-ui/master/install.sh)`
    得到了方便失去了安全
    artieo
        48
    artieo  
       2023-09-09 05:55:41 +08:00
    nginx -t 检查配置文件,可能是不存在 www-data 用户的问题,页面不一样可能是浏览器缓存导致的
    encro
        49
    encro  
       2023-09-09 12:42:08 +08:00
    标准流程应该是新增/etc/nginx/sites-enabled/domain-name.conf 。让后 nginx -t ,然后 nginx -s reload 。

    然后在服务器上 curl 看结果,然后远程 curl 看结果。


    https 可以使用 certbot 的 nginx 插件,支持阿里云,腾讯云,以及国外一堆主流的。
    MeteorCat
        50
    MeteorCat  
       2023-09-09 14:27:56 +08:00 via Android
    开 ssh ,让楼上看看
    chenli100681
        51
    chenli100681  
    OP
       2023-09-09 14:59:13 +08:00
    @artieo #47 确实我还是用 xui 吧,感谢!我看 projectx 的 channel 里面说过 xui 因为是 http 明文访问不是很安全
    chenli100681
        52
    chenli100681  
    OP
       2023-09-09 14:59:34 +08:00
    @MeteorCat #50 逆天
    chenli100681
        53
    chenli100681  
    OP
       2023-09-09 15:00:45 +08:00
    @encro #49 呐,这个就叫专业,我自己再了解一下吧
    chenli100681
        54
    chenli100681  
    OP
       2023-09-09 15:06:18 +08:00 via Android
    @artieo 不过大佬们都是怎会会这些的有什么学习路线吗
    artieo
        55
    artieo  
       2023-09-10 20:10:57 +08:00
    @chenli100681 先随机一个密码登上去改成 https,然后再改密码
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     3302 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 29ms UTC 11:47 PVG 19:47 LAX 04:47 JFK 07:47
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86