![nginx: [emerg] ここでは「location」ディレクティブは許可されていません](https://rvso.com/image/658822/nginx%3A%20%5Bemerg%5D%20%E3%81%93%E3%81%93%E3%81%A7%E3%81%AF%E3%80%8Clocation%E3%80%8D%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%86%E3%82%A3%E3%83%96%E3%81%AF%E8%A8%B1%E5%8F%AF%E3%81%95%E3%82%8C%E3%81%A6%E3%81%84%E3%81%BE%E3%81%9B%E3%82%93.png)
私のウェブパネルのページには.htaccessファイルが必要ですが、現在Nginxを使用しているため、.htaccessの書き換えをNginxで動作するように変換する必要があります。オンラインコンバータを使用しました。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 の設定をもっと詳しく勉強することをお勧めします。そうしないと、将来的に問題が発生するだけです。