[英]".htaccess" data to Nginx file migration
I was using Apache and Nginx together before in CWP and I will start using ISPconfig from today, but I am having some problems.我之前在 CWP 中一起使用了 Apache 和 Nginx,我将从今天开始使用 ISPconfig,但我遇到了一些问题。 I would be glad if you can help with this.
如果您能提供帮助,我会很高兴。
There are .htaccess
files with different content in subdomains.子域中有不同内容的
.htaccess
文件。 I need to use it in the file, and the issue starts here.我需要在文件中使用它,问题从这里开始。
Here is a sample .htaccess
file content that I used before: (for a subdomain: panel.example.com
)这是我之前使用的示例
.htaccess
文件内容:(对于子域: panel.example.com
)
Code:代码:
RewriteEngine on
RewriteBase /
# If the request doesn't end in .php (Case insensitive) continue processing rules
RewriteCond %{REQUEST_URI} !\.php$ [NC]
# If the request doesn't end in a slash continue processing the rules
RewriteCond %{REQUEST_URI} [^/]$
# Rewrite the request with a .php extension. L means this is the 'Last' rule
RewriteRule ^(.*)$ $1.php [L]
# The following require certain allow overrides, if getting 500 error comment them out one by one
# can be resolved in apache httpd.conf to ensure security alternatives
## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
RewriteCond %{REQUEST_URI} !.(css|gif|ico|jpg|js|png|swf|txt)$
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)?$ index.php?cmd=$1&scd=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?cmd=$1 [L,QSA]
I converted the above code to:我将上面的代码转换为:
Code:代码:
rewrite ^/([^/]+)/([^/]+)?$ /index.php?cmd=$1&scd=$2 last;
rewrite ^/([^/]+)/?$ /index.php?cmd=$1 last;
I will add the new code to the example.com.vhost
file located in /etc/nginx/sites-available/
, but where exactly do I add it in conf.我会将新代码添加到
example.com.vhost
文件中,该文件位于/etc/nginx/sites-available/
中,但我将它添加到 conf. file?文件?
Nginx Conf. Nginx 会议。 File:
文件:
server {
listen *:80;
listen [::]:80;
listen *:443 ssl http2;
ssl_protocols TLSv1.3 TLSv1.2;
listen [::]:443 ssl http2;
ssl_certificate /var/www/clients/client4/web3/ssl/example.com-le.crt;
ssl_certificate_key /var/www/clients/client4/web3/ssl/example.com-le.key;
server_name example.com www.example.com panel.example.com assets.example.com storage.example.com help.example.com api.example.com;
root /var/www/example.com/web/;
disable_symlinks if_not_owner from=$document_root;
if ($http_host = "panel.example.com") {
rewrite ^(?!/(_SubDomains/Panel|stats|\.well-known/acme-challenge))/(.*)$ /_SubDomains/Panel/$2 last;
## HERE ?
}
if ($http_host = "assets.example.com") {
rewrite ^(?!/(_SubDomains/Assets|stats|\.well-known/acme-challenge))/(.*)$ /_SubDomains/Assets/$2 last;
}
if ($http_host = "storage.example.com") {
rewrite ^(?!/(_SubDomains/Storage|stats|\.well-known/acme-challenge))/(.*)$ /_SubDomains/Storage/$2 last;
}
if ($http_host = "help.example.com") {
rewrite ^(?!/(_SubDomains/Help|stats|\.well-known/acme-challenge))/(.*)$ /_SubDomains/Help/$2 last;
}
if ($http_host = "api.example.com") {
rewrite ^(?!/(_SubDomains/Api|stats|\.well-known/acme-challenge))/(.*)$ /_SubDomains/Api/$2 last;
}
index index.html index.htm index.php index.cgi index.pl index.xhtml standard_index.html;
error_log /var/log/ispconfig/httpd/example.com/error.log;
access_log /var/log/ispconfig/httpd/example.com/access.log combined;
location ~ /\. {
deny all;
}
location ^~ /.well-known/acme-challenge/ {
access_log off;
log_not_found off;
auth_basic off;
root /usr/local/ispconfig/interface/acme/;
autoindex off;
index index.html;
try_files $uri $uri/ =404;
}
location = /favicon.ico {
log_not_found off;
access_log off;
expires max;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location /stats/ {
index index.html index.php;
auth_basic "Members Only";
auth_basic_user_file /var/www/clients/client4/web3/web//stats/.htpasswd_stats;
add_header Content-Security-Policy "default-src * 'self' 'unsafe-inline' 'unsafe-eval' data:;";
}
location ^~ /awstats-icon {
alias /usr/share/awstats/icon;
}
location ~ \.php$ {
try_files /ba758c370926ab55427f2160db29ee1d.htm @php;
}
location @php {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/lib/php7.4-fpm/web3.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
}
Thank you.谢谢你。
Yes you can add you rewrite directives in that place which you marked in config.是的,您可以在配置中标记的那个地方添加重写指令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.