【问题标题】:Nginx Error When Editing Config编辑配置时出现 Nginx 错误
【发布时间】:2023-03-25 18:23:01
【问题描述】:

我一直在尝试使用 nginx 作为我的服务器来安装 flarum,但是当我重新启动 nginx 时,我会遇到多个问题,如果有人能找出我出错的地方,我将不胜感激

当我运行“systemctl restart nginx”时会发生这种情况

nginx.service 的作业失败,因为控制进程以错误代码退出。详见“systemctl status nginx.service”和“journalctl -xe”。

然后当我运行“nginx -t -c /etc/nginx/nginx.conf”时会发生这种情况

nginx:[emerg] /etc/nginx/sites-enabled/creativethoughts:14 中的重复位置“/” nginx:配置文件 /etc/nginx/nginx.conf 测试失败

这是我上次重启 nginx 后所做的事情

创建一个新的站点可用文件,然后使用“sudo ln -s /etc/nginx/sites-available/creativethoughts /etc/nginx/sites-enabled/”将其复制到站点启用

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /var/www/html;
index index.html index.htm;

server_name forums.creativethoughts.us      www.forums.creativethoughts.us;

location / {
    try_files $uri $uri/ =404;
}

location / { try_files $uri $uri/ /index.php?$query_string; }
location /api { try_files $uri $uri/ /api.php?$query_string; }
location /admin { try_files $uri $uri/ /admin.php?$query_string; }

location /flarum {
    deny all;
    return 404;
}

location ~* \.php$ {
    fastcgi_split_path_info ^(.+.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTP_PROXY ""; # Fix for https://httpoxy.org/ vulnerability
    fastcgi_index index.php;
}

location ~* \.html$ {
    expires -1;
}

location ~* \.(css|js|gif|jpe?g|png)$ {
    expires 1M;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types application/atom+xml
           application/javascript
           application/json
           application/vnd.ms-fontobject
           application/x-font-ttf
           application/x-web-app-manifest+json
           application/xhtml+xml
           application/xml
           font/opentype
           image/svg+xml
           image/x-icon
           text/css
           text/plain
           text/xml;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

}

------------------------------------------ ------

编辑了 nginx.conf 并删除了 "server_names_hash_bucket_size 64;" 中的注释

终于尝试重启,报错

【问题讨论】:

    标签: nginx


    【解决方案1】:
    1. 您指定了两次/ 位置。
    2. 您已多次声明 gzip 指令。
    3. 您没有关闭服务器块。

    这里是固定的:

    server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    
    root /var/www/html;
    index index.html index.htm;
    
    server_name forums.creativethoughts.us      www.forums.creativethoughts.us;
    
    location / { try_files $uri $uri/ /index.php?$query_string; }
    location /api { try_files $uri $uri/ /api.php?$query_string; }
    location /admin { try_files $uri $uri/ /admin.php?$query_string; }
    
    location /flarum {
        deny all;
        return 404;
    }
    
    location ~* \.php$ {
        fastcgi_split_path_info ^(.+.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTP_PROXY ""; # Fix for https://httpoxy.org/ vulnerability
        fastcgi_index index.php;
    }
    
    location ~* \.html$ {
        expires -1;
    }
    
    location ~* \.(css|js|gif|jpe?g|png)$ {
        expires 1M;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }
    }
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_proxied any;
    gzip_types application/atom+xml
               application/javascript
               application/json
               application/vnd.ms-fontobject
               application/x-font-ttf
               application/x-web-app-manifest+json
               application/xhtml+xml
               application/xml
               font/opentype
               image/svg+xml
               image/x-icon
               text/css
               text/plain
               text/xml;
    gzip_buffers 16 8k;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    

    【讨论】:

      猜你喜欢
      • 2017-11-20
      • 1970-01-01
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-23
      • 2019-04-09
      相关资源
      最近更新 更多