NGINX conf 2 个域名 + 子域名位于单独的根文件夹中,并将 www 更改为非 www

NGINX conf 2 个域名 + 子域名位于单独的根文件夹中,并将 www 更改为非 www

我尝试为两个域创建 2 个单独的 NGINX conf 文件。每个域都有一个 test. 子域,并且出于规范原因,www 应永久重定向到 now-www。我在下面的代码中收到 2 个错误。

sudo nginx -t nginx:[warn] 服务器名称“$uri/”在 /etc/nginx/sites-enabled/example.com:27 中有可疑符号 nginx:[warn] 服务器名称“/index.php$is_args$args”在 /etc/nginx/sites-enabled/example.com:27 中有可疑符号 nginx:[emerg] /etc/nginx/sites-enabled/example.com:31 中不允许使用“location”指令 nginx:配置文件 /etc/nginx/nginx.conf 测试失败

这是我的 example.com 的 conf 文件,example2 的第二个文件几乎相同。

 server {
 listen 80;
 listen [::]:80;
 root /var/www/example.com/html;
 index index.php index.html index.htm index.nginx-debian.html;
 server_name example.com 123.456.7.8;
 #location / {
 #try_files $uri $uri/ =404;
 try_files $uri $uri/ /index.php$is_args$args;
 #(For WordPress permalinks)
 }
 # Redirect all traffic to www to non-www for SEO canonical reasons server
 server {
 listen 80; server_name www.example.com;
 location / { return 301 https://www.example.com/$request_uri; }
 location ~ /.well-known/acme-challenge/ { default_type "text/plain";
 root /usr/share/nginx/html; allow all; }
 }
 # Direct all traffic to the  subdomain to a separate folder
 server {
 listen 80;
 listen [::]:80;
 root /var/www/test/example.com/html;
 index index.php index.html index.htm index.nginx-debian.html;
 server_name test.example.com

 try_files $uri $uri/ /index.php$is_args$args;
 #(For WordPress permalinks)
 }
 # include /etc/nginx/naxsi.rules
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass unix:/run/php/php7.4-fpm.sock;
 }
 location = /favicon.ico { log_not_found off; access_log off; }
 location = /robots.txt { log_not_found off; access_log off; allow all; }
 location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
 expires max;
 #To enable leverage browser caching log_not_found off;
 }
 }
 

相关内容