VPS侦探论坛

 找回密码
 注册
查看: 1433|回复: 7

[Nginx] 内网穿透,网站除首页外不能使用域名,该如何设置?

[复制链接]
发表于 2023-4-18 09:09:39 | 显示全部楼层 |阅读模式

如题问题,lnmp是1.9版本的,安装zblog,首页能够显示,但是CSS文件就不能加载了,使用本地IP访问就是一切正常的。
用的树莓派3B+


  1. uname -a

  2. Linux raspberrypi 6.1.21-v7+ #1642 SMP Mon Apr  3 17:20:52 BST 2023 armv7l GNU/Linux
复制代码
系统是树莓派官方系统
  1. cat /etc/os-release
复制代码
vhost的conf用的默认的,没有任何修改
  1. server
  2.     {
  3.         listen 80;
  4.         #listen [::]:80;
  5.         server_name 我设置的域名 ;
  6.         index index.html index.htm index.php default.html default.htm default.php;
  7.         root  /home/wwwroot/我设置的域名;

  8.         include rewrite/zblog.conf;
  9.         #error_page   404   /404.html;

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

  12.         include enable-php.conf;

  13.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  14.         {
  15.             expires      30d;
  16.         }

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

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

  24.         location ~ /\.
  25.         {
  26.             deny all;
  27.         }

  28.         access_log  /home/wwwlogs/我设置的域名.log;
  29.     }
复制代码
nginx的conf也没有修改,默认生成的内容
  1. user  www www;

  2. worker_processes auto;
  3. worker_cpu_affinity auto;

  4. error_log  /home/wwwlogs/nginx_error.log  crit;

  5. pid        /usr/local/nginx/logs/nginx.pid;

  6. #Specifies the value for maximum file descriptors that can be opened by this process.
  7. worker_rlimit_nofile 51200;

  8. events
  9.     {
  10.         use epoll;
  11.         worker_connections 51200;
  12.         multi_accept off;
  13.         accept_mutex off;
  14.     }

  15. http
  16.     {
  17.         include       mime.types;
  18.         default_type  application/octet-stream;

  19.         server_names_hash_bucket_size 128;
  20.         client_header_buffer_size 32k;
  21.         large_client_header_buffers 4 32k;
  22.         client_max_body_size 50m;

  23.         sendfile on;
  24.         sendfile_max_chunk 512k;
  25.         tcp_nopush on;

  26.         keepalive_timeout 60;

  27.         tcp_nodelay on;

  28.         fastcgi_connect_timeout 300;
  29.         fastcgi_send_timeout 300;
  30.         fastcgi_read_timeout 300;
  31.         fastcgi_buffer_size 64k;
  32.         fastcgi_buffers 4 64k;
  33.         fastcgi_busy_buffers_size 128k;
  34.         fastcgi_temp_file_write_size 256k;

  35.         gzip on;
  36.         gzip_min_length  1k;
  37.         gzip_buffers     4 16k;
  38.         gzip_http_version 1.1;
  39.         gzip_comp_level 2;
  40.         gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
  41.         gzip_vary on;
  42.         gzip_proxied   expired no-cache no-store private auth;
  43.         gzip_disable   "MSIE [1-6]\.";

  44.         #limit_conn_zone $binary_remote_addr zone=perip:10m;
  45.         ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

  46.         server_tokens off;
  47.         access_log off;

  48. server
  49.     {
  50.         listen 80 default_server reuseport;
  51.         #listen [::]:80 default_server ipv6only=on;
  52.         server_name _;
  53.         index index.html index.htm index.php;
  54.         root  /home/wwwroot/default;

  55.         #error_page   404   /404.html;

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

  58.         include enable-php.conf;

  59.         location /nginx_status
  60.         {
  61.             stub_status on;
  62.             access_log   off;
  63.         }

  64.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  65.         {
  66.             expires      30d;
  67.         }

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

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

  75.         location ~ /\.
  76.         {
  77.             deny all;
  78.         }

  79.         access_log  /home/wwwlogs/access.log;
  80.     }
  81. include vhost/*.conf;
  82. }
复制代码
想请问的是这要如何去设置?才能让域名访问正常,谢谢。
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2023-4-18 09:12:38 | 显示全部楼层


没看到修改帖子的链接在哪里,补充系统信息,可能前面复制的时候漏掉了:
  1. PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
  2. NAME="Raspbian GNU/Linux"
  3. VERSION_ID="11"
  4. VERSION="11 (bullseye)"
  5. VERSION_CODENAME=bullseye
  6. ID=raspbian
  7. ID_LIKE=debian
  8. HOME_URL="http://www.raspbian.org/"
  9. SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
  10. BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
复制代码
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2023-4-18 09:56:36 | 显示全部楼层

在zblog的常见问题里找到了一个解决办法,
明确需要指定域名使用

使用空间面板的文件管理或者 FTP 修改文件:path/zb_users/c_option.php;

配置项:
  1. 'ZC_PERMANENT_DOMAIN_FORCED_URL' => "https://www.newdomin.site/",
复制代码


path:当前博客程序所放置的路径,比如/home/wwwroot/www.zblogcn.com;

这样可以解决这个显示正常的问题。

但是新增了网站不会自己关联是吗?必须要手动修改nginx.conf文件吗?多个域名对应多个网站要怎么处理?目前我是直接把nginx.conf里server里面的内容全部删除了。
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2023-4-18 14:54:29 | 显示全部楼层



1、先不说内网穿透,如果用域名访问,ip只能访问到lnmp默认页面,如果访问用域名访问到默认页面说明添加的域名未生效或有其他问题导致未生效
2、内网环境下先改本机hosts测试添加的域名是否正常访问
3、内网穿透下查看网站源码,查看css部分链接代码是怎样的?
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2023-4-18 15:11:19 | 显示全部楼层

感谢解答:
1、IP和域名访问都只能访问默认页面,vhost的设置没有起作用,把nginx.conf里的server部分全部删除后可以访问设置的网站,vhost里的conf起作用了,因为第一次用lnmp,不太清楚要怎么设置,所以也没有修改任何设置。
2、内网环境访问只会访问默认页面,如果多个虚拟机要怎么访问其它网站?这里不会操作。
3、查看CSS部分是直接内网IP,用了zblog官方问答的方法解决了这个问题。

军哥运维代购:http://shop63846532.taobao.com/

发表于 2023-4-18 20:09:05 | 显示全部楼层

xujue 发表于 2023-4-18 15:11
感谢解答:
1、IP和域名访问都只能访问默认页面,vhost的设置没有起作用,把nginx.conf里的server部分全部 ...

lnmp vhost add 添加的吗?
nginx -t 测试一下配置文件是否报错
没错误的话 /etc/init.d/nginx restart 重启nginx配置文件就会生效特殊情况下还可以尝试kill nginx的pid再启动或者重启系统
 楼主| 发表于 2023-4-19 01:19:20 | 显示全部楼层

是用lnmp vhost add 添加的,测试要开 sudo 才通过。
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2023-4-19 17:46:06 | 显示全部楼层

xujue 发表于 2023-4-19 01:19
是用lnmp vhost add 添加的,测试要开 sudo 才通过。

重启了没?
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-5-4 12:54 , Processed in 0.028366 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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