![nginx: [emerg] 여기서는 "location" 지시문이 허용되지 않습니다.](https://rvso.com/image/658822/nginx%3A%20%5Bemerg%5D%20%EC%97%AC%EA%B8%B0%EC%84%9C%EB%8A%94%20%22location%22%20%EC%A7%80%EC%8B%9C%EB%AC%B8%EC%9D%B4%20%ED%97%88%EC%9A%A9%EB%90%98%EC%A7%80%20%EC%95%8A%EC%8A%B5%EB%8B%88%EB%8B%A4..png)
내 웹 패널의 페이지에는 .htaccess 파일이 필요하며 현재 Nginx를 사용하고 있으므로 Nginx에서 작동하도록 .htaccess 다시 쓰기를 변환해야 합니다. 온라인 변환기를 사용했습니다http://winginx.com/en/htaccess무엇을 입력해야 하는지 알려주었고 변경 사항을 저장하기 위해 Nginx를 다시 시작할 때 오류가 발생했습니다.
원본 .htaccess 재작성:
Options -Indexes
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)(\.)(.*)$ index.php?url=$1.$3 [L,QSA]
RewriteRule ^ajax$ _res/ajax.php [QSA]
#RewriteRule ^(.*)$ index.php?t=$1 [L,QSA]
</IfModule>
변환:
# nginx configuration
location = /favicon.ico {
}
autoindex off;
location / {
if (!-e $request_filename){
rewrite ^/(.*)(\.)(.*)$ /index.php?url=$1.$3 break;
}
}
location = /ajax {
rewrite ^(.*)$ /_res/ajax.php;
}
변환 코드가 포함된 구성 파일:
# redirect from non-www to www
# uncomment, save file and restart Nginx to enable
#server {
# listen 80;
# server_name domain.com;
# return 301 $scheme://www.domain.com$request_uri;
# }
server {
# Cloudflare
set_real_ip_from 199.27.128.0/21;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/12;
real_ip_header CF-Connecting-IP;
server_name domain.com www.domain.com;
# ngx_pagespeed & ngx_pagespeed handler
#include /usr/local/nginx/conf/pagespeed.conf;
#include /usr/local/nginx/conf/pagespeedhandler.conf;
#include /usr/local/nginx/conf/pagespeedstatslog.conf;
# limit_conn limit_per_ip 16;
# ssi on;
access_log /home/nginx/domains/domain.com/log/access.log combined buffer=32k;
error_log /home/nginx/domains/domain.com/log/error.log;
root /home/nginx/domains/domain.com/public;
location / {
# block common exploits, sql injections etc
#include /usr/local/nginx/conf/block.conf;
# Enables directory listings when index file not found
#autoindex on;
# Shows file listing times as local time
#autoindex_localtime on;
# Enable for vBulletin usage WITHOUT vbSEO installed
#try_files $uri $uri/ /index.php;
}
include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/php.conf;
include /usr/local/nginx/conf/drop.conf;
#include /usr/local/nginx/conf/errorpage.conf;
}
# nginx configuration
location = /favicon.ico {
}
autoindex off;
location / {
if (!-e $request_filename){
rewrite ^/(.*)(\.)(.*)$ /index.php?url=$1.$3 break;
}
}
location = /ajax {
rewrite ^(.*)$ /_res/ajax.php;
}
오류:
[root@radio ~]# nginx: [emerg] "location" directive is not allowed here in /usr/local/nginx/conf/conf.d/domain.com.conf:65
대체로 코드를 올바른 위치에 배치했는지 또는 무엇을 배치했는지 잘 모르겠습니다. 하지만 현재로서는 위와 같은 오류가 발생합니다.
감사합니다!
답변1
블록 location
이 잘못된 위치에 있습니다. 블록 안에 있어야 합니다 server
.
전체 개념을 이해하려면 nginx 구성을 훨씬 더 자세히 연구하는 것이 좋습니다. 그렇지 않으면 앞으로 문제만 생길 것입니다.