我在我的 nginx 服务器上安装了 Datalife Engine (cms),实际上一切都运行良好,直到从此 cms 访问 html 类别时显示 404 未找到。我以为它是 htaccess 文件,但我不知道我们不能在 apache 等目录中使用 htaccess。所以我检查了 htaccess 文件,这些是转换的(apache 到 nginxhttps://winginx.com/en/htaccesscodes):
# nginx configuration by winginx.com
index index.php;
location /page {
rewrite ^/page/([0-9]+)(/?)$ /index.php?cstart=$1 break;
rewrite ^/page,([0-9]+),([0-9]+),([0-9]+)-(.*).html$ /index.php?newsid=$3&news_page=$1&cstart=$2&seourl=$4 break;
rewrite ^/page,([0-9]+),([0-9]+)-(.*).html$ /index.php?newsid=$2&news_page=$1&seourl=$3 break;
rewrite ^/page,([0-9]+),([^/]+).html$ /index.php?do=static&page=$2&news_page=$1&seourl=$2 break;
}
location / {
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/page,([0-9]+),([0-9]+),(.*).html$" /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&cstart=$5&news_name=$6&seourl=$6 break;
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/page,([0-9]+),(.*).html$" /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&news_name=$5&seourl=$5 break;
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/print:page,([0-9]+),(.*).html$" /index.php?mod=print&subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&news_name=$5&seourl=$5 break;
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*).html$" /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_name=$4&seourl=$4 break;
rewrite ^/([^.]+)/page,([0-9]+),([0-9]+),([0-9]+)-(.*).html$ /index.php?newsid=$4&news_page=$2&cstart=$3&seourl=$5&seocat=$1 break;
rewrite ^/([^.]+)/page,([0-9]+),([0-9]+)-(.*).html$ /index.php?newsid=$3&news_page=$2&seourl=$4&seocat=$1 break;
rewrite ^/([^.]+)/print:page,([0-9]+),([0-9]+)-(.*).html$ /index.php?mod=print&news_page=$2&newsid=$3&seourl=$4&seocat=$1 break;
rewrite ^/([^.]+)/([0-9]+)-(.*).html$ /index.php?newsid=$2&seourl=$3&seocat=$1 break;
rewrite ^/([0-9]+)-(.*).html$ /index.php?newsid=$1&seourl=$2 break;
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/*$" /index.php?year=$1&month=$2&day=$3 break;
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/page/([0-9]+)/*$" /index.php?year=$1&month=$2&day=$3&cstart=$4 break;
rewrite "^/([0-9]{4})/([0-9]{2})/*$" /index.php?year=$1&month=$2 break;
rewrite "^/([0-9]{4})/([0-9]{2})/page/([0-9]+)/*$" /index.php?year=$1&month=$2&cstart=$3 break;
rewrite "^/([0-9]{4})/*$" /index.php?year=$1 break;
rewrite "^/([0-9]{4})/page/([0-9]+)/*$" /index.php?year=$1&cstart=$2 break;
if (!-e $request_filename){
rewrite ^/([^.]+)/page/([0-9]+)/*$ /index.php?do=cat&category=$1&cstart=$2 break;
}
rewrite ^/([^.]+)/?$ /index.php?do=cat&category=$1 break;
if (!-e $request_filename){
rewrite ^/([^.]+)/rss.xml$ /index.php?mod=rss&do=cat&category=$1 break;
}
if (!-e $request_filename){
rewrite ^/([^/]+).html$ /index.php?do=static&page=$1&seourl=$1 break;
}
}
location /print {
rewrite ^/print:page,([0-9]+),([0-9]+)-(.*).html$ /index.php?mod=print&news_page=$1&newsid=$2&seourl=$3 break;
rewrite ^/print:([^/]+).html$ /index.php?mod=print&do=static&page=$1&seourl=$1 break;
}
location /tags {
rewrite ^/tags/([^/]*)/*$ /index.php?do=tags&tag=$1 break;
rewrite ^/tags/([^/]*)/page/([0-9]+)/*$ /index.php?do=tags&tag=$1&cstart=$2 break;
}
location /xfsearch {
rewrite ^/xfsearch/(.*)/page/([0-9]+)/*$ /index.php?do=xfsearch&xf=$1&cstart=$2 break;
rewrite ^/xfsearch/(.*)/?$ /index.php?do=xfsearch&xf=$1 break;
}
location /user {
rewrite ^/user/([^/]*)/rss.xml$ /index.php?mod=rss&subaction=allnews&user=$1 break;
rewrite ^/user/([^/]*)/*$ /index.php?subaction=userinfo&user=$1 break;
rewrite ^/user/([^/]*)/page/([0-9]+)/*$ /index.php?subaction=userinfo&user=$1&cstart=$2 break;
rewrite ^/user/([^/]*)/news/*$ /index.php?subaction=allnews&user=$1 break;
rewrite ^/user/([^/]*)/news/page/([0-9]+)/*$ /index.php?subaction=allnews&user=$1&cstart=$2 break;
rewrite ^/user/([^/]*)/news/rss.xml/*$ /index.php?mod=rss&subaction=allnews&user=$1 break;
}
location /lastnews {
rewrite ^/lastnews/*$ /index.php?do=lastnews break;
rewrite ^/lastnews/page/([0-9]+)/*$ /index.php?do=lastnews&cstart=$1 break;
}
location /catalog {
rewrite ^/catalog/([^/]*)/rss.xml$ /index.php?mod=rss&catalog=$1 break;
rewrite ^/catalog/([^/]*)/*$ /index.php?catalog=$1 break;
rewrite ^/catalog/([^/]*)/page/([0-9]+)/*$ /index.php?catalog=$1&cstart=$2 break;
}
location /newposts {
rewrite ^/newposts/*$ /index.php?subaction=newposts break;
rewrite ^/newposts/page/([0-9]+)/*$ /index.php?subaction=newposts&cstart=$1 break;
}
location /favorites {
rewrite ^/favorites/*$ /index.php?do=favorites break;
rewrite ^/favorites/page/([0-9]+)/*$ /index.php?do=favorites&cstart=$1 break;
}
location = /rules.html {
rewrite ^(.*)$ /index.php?do=rules break;
}
location = /statistics.html {
rewrite ^(.*)$ /index.php?do=stats break;
}
location = /addnews.html {
rewrite ^(.*)$ /index.php?do=addnews break;
}
location = /rss.xml {
rewrite ^(.*)$ /index.php?mod=rss break;
}
location = /sitemap.xml {
rewrite ^(.*)$ /uploads/sitemap.xml break;
}
这是我的默认配置(默认):
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
location /phpmyadmin {
root /usr/share/;
index index.php;
try_files $uri $uri/ =404;
location ~ ^/phpmyadmin/(doc|sql|setup)/ {
deny all;
}
location ~ /phpmyadmin/(.+\.php)$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi-php.conf;
}
}
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name 192.168.1.107;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?q=$uri&$args;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
我该如何修复 404 not found 问题?能否使用 htaccess 修复?如果可能的话,我该如何使用此配置而不出现任何错误?!照片:404 未找到 HTML 页面
答案1
尝试这个
# nginx configuration
index index.php;
location /page {
rewrite ^/page/([0-9]+)(/?)$ /index.php?cstart=$1 break;
rewrite ^/page,([0-9]+),([0-9]+),([0-9]+)-(.*).html$ /index.php?newsid=$3&news_page=$1&cstart=$2&seourl=$4 break;
rewrite ^/page,([0-9]+),([0-9]+)-(.*).html$ /index.php?newsid=$2&news_page=$1&seourl=$3 break;
rewrite ^/page,([0-9]+),([^/]+).html$ /index.php?do=static&page=$2&news_page=$1&seourl=$2 break;
}
location / {
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/page,([0-9]+),([0-9]+),(.*).html$" /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&cstart=$5&news_name=$6&seourl=$6 break;
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/page,([0-9]+),(.*).html$" /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&news_name=$5&seourl=$5 break;
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/print:page,([0-9]+),(.*).html$" /index.php?mod=print&subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&news_name=$5&seourl=$5 break;
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*).html$" /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_name=$4&seourl=$4 break;
rewrite ^/([^.]+)/page,([0-9]+),([0-9]+),([0-9]+)-(.*).html$ /index.php?newsid=$4&news_page=$2&cstart=$3&seourl=$5&seocat=$1 break;
rewrite ^/([^.]+)/page,([0-9]+),([0-9]+)-(.*).html$ /index.php?newsid=$3&news_page=$2&seourl=$4&seocat=$1 break;
rewrite ^/([^.]+)/print:page,([0-9]+),([0-9]+)-(.*).html$ /index.php?mod=print&news_page=$2&newsid=$3&seourl=$4&seocat=$1 break;
rewrite ^/([^.]+)/([0-9]+)-(.*).html$ /index.php?newsid=$2&seourl=$3&seocat=$1 break;
rewrite ^/([0-9]+)-(.*).html$ /index.php?newsid=$1&seourl=$2 break;
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/*$" /index.php?year=$1&month=$2&day=$3 break;
rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/page/([0-9]+)/*$" /index.php?year=$1&month=$2&day=$3&cstart=$4 break;
rewrite "^/([0-9]{4})/([0-9]{2})/*$" /index.php?year=$1&month=$2 break;
rewrite "^/([0-9]{4})/([0-9]{2})/page/([0-9]+)/*$" /index.php?year=$1&month=$2&cstart=$3 break;
rewrite "^/([0-9]{4})/*$" /index.php?year=$1 break;
rewrite "^/([0-9]{4})/page/([0-9]+)/*$" /index.php?year=$1&cstart=$2 break;
if (!-e $request_filename){
rewrite ^/([^.]+)/page/([0-9]+)/*$ /index.php?do=cat&category=$1&cstart=$2 break;
}
rewrite ^/([^.]+)/?$ /index.php?do=cat&category=$1 break;
if (!-e $request_filename){
rewrite ^/([^.]+)/rss.xml$ /index.php?mod=rss&do=cat&category=$1 break;
}
if (!-e $request_filename){
rewrite ^/([^/]+).html$ /index.php?do=static&page=$1&seourl=$1 break;
}
}
location /print {
rewrite ^/print:page,([0-9]+),([0-9]+)-(.*).html$ /index.php?mod=print&news_page=$1&newsid=$2&seourl=$3 break;
rewrite ^/print:([^/]+).html$ /index.php?mod=print&do=static&page=$1&seourl=$1 break;
}
location /tags {
rewrite ^/tags/([^/]*)/*$ /index.php?do=tags&tag=$1 break;
rewrite ^/tags/([^/]*)/page/([0-9]+)/*$ /index.php?do=tags&tag=$1&cstart=$2 break;
}
location /xfsearch {
rewrite ^/xfsearch/(.*)/page/([0-9]+)/*$ /index.php?do=xfsearch&xf=$1&cstart=$2 break;
rewrite ^/xfsearch/(.*)/?$ /index.php?do=xfsearch&xf=$1 break;
}
location /user {
rewrite ^/user/([^/]*)/rss.xml$ /index.php?mod=rss&subaction=allnews&user=$1 break;
rewrite ^/user/([^/]*)/*$ /index.php?subaction=userinfo&user=$1 break;
rewrite ^/user/([^/]*)/page/([0-9]+)/*$ /index.php?subaction=userinfo&user=$1&cstart=$2 break;
rewrite ^/user/([^/]*)/news/*$ /index.php?subaction=allnews&user=$1 break;
rewrite ^/user/([^/]*)/news/page/([0-9]+)/*$ /index.php?subaction=allnews&user=$1&cstart=$2 break;
rewrite ^/user/([^/]*)/news/rss.xml/*$ /index.php?mod=rss&subaction=allnews&user=$1 break;
}
location /lastnews {
rewrite ^/lastnews/*$ /index.php?do=lastnews break;
rewrite ^/lastnews/page/([0-9]+)/*$ /index.php?do=lastnews&cstart=$1 break;
}
location /catalog {
rewrite ^/catalog/([^/]*)/rss.xml$ /index.php?mod=rss&catalog=$1 break;
rewrite ^/catalog/([^/]*)/*$ /index.php?catalog=$1 break;
rewrite ^/catalog/([^/]*)/page/([0-9]+)/*$ /index.php?catalog=$1&cstart=$2 break;
}
location /newposts {
rewrite ^/newposts/*$ /index.php?subaction=newposts break;
rewrite ^/newposts/page/([0-9]+)/*$ /index.php?subaction=newposts&cstart=$1 break;
}
location = /feedback.html {
rewrite ^(.*)$ /index.php?do=feedback break;
}
location = /register.html {
rewrite ^(.*)$ /index.php?do=register break;
}
location /favorites {
rewrite ^/favorites/*$ /index.php?do=favorites break;
rewrite ^/favorites/page/([0-9]+)/*$ /index.php?do=favorites&cstart=$1 break;
}
location = /rules.html {
rewrite ^(.*)$ /index.php?do=rules break;
}
location = /statistics.html {
rewrite ^(.*)$ /index.php?do=stats break;
}
location = /addnews.html {
rewrite ^(.*)$ /index.php?do=addnews break;
}
location = /rss.xml {
rewrite ^(.*)$ /index.php?mod=rss break;
}
location = /sitemap.xml {
rewrite ^(.*)$ /uploads/sitemap.xml break;
}