0
방금 Nginx를 실험하기 시작했으나 구성에 문제가 있습니다. 다음을 달성하고 싶습니다.Nginx가 index.php에 대한 모든 내용을 다시 작성하는 이유는 무엇입니까?
- 모든 트래픽을
index.php
으로 리디렉션하고 싶습니다. 따라서 라우팅을 사용하여 깨끗한 URL을 만들 수 있습니다.
시 저는 URL을 다시 작성하고 싶습니다. 나는이 구성 아파치를 사용했습니다 전에 :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?q=$1 [QSA,L]
이 아파치 규칙은 index.php
에 모든 트래픽을 리디렉션. 나는 Nginx와 동일하게하고 싶다.
나는 지금까지이 코드를 가지고있다. 그러나 정말로 wokrking하지는 않는다. 그것은 502 오류와 403 오류를 제공합니다.
server {
error_log /var/log/nginx/vhost-error_log warn;
listen *.*.*.*:80;
listen [::]:80;
server_name ***.com www.***.com;
access_log /usr/local/apache/domlogs/***.com-bytes_log bytes_log;
access_log /usr/local/apache/domlogs/***.com combined;
root /home/***/public_html;
#location/{
location ~*.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
expires 1M;
try_files $uri @backend;
}
location @backend {
internal;
proxy_pass http://*.*.*.*:8081;
include proxy.inc;
include microcache.inc;
}
location ~ /\.ht {
deny all;
}
location/{
set $page_to_view "/index.php";
try_files $uri $uri/ @rewrites;
root /home/***/www/public_html/ ;
index index.php index.html index.htm;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/***/www/public_html/$page_to_view;
}
# rewrites
location @rewrites {
if ($uri ~* ^/([a-z]+)$) {
set $page_to_view "/$1.php";
rewrite ^/([a-z]+)$ /$1.php last;
}
}
}
나는 이것이 원래 설정과 내가 Google에서 발견 한 것의 혼합이라고 알고 있습니다. 아무도 내가 도와 줄 수 있을까요? 내가 쓸만한 파일을 어떻게 만들어야합니까?