我很难弄清楚如何配置 Nginx。基本上,我有相同的服务器名称,但有两个网站:
- 网站 x 根文件夹:/var/www/html/x/public
- Wordpress 根文件夹:/var/www/html/wordpress
当我访问 localhost:8443 时,它将转到:/var/www/html/x/public 当我访问 localhost:8443/blog 时,它将转到:/var/www/html/wordpress
我设法使其工作到某个程度,其中 localhost:8443/blog 可以工作,但是 localhost:8443/blog/my-blog-post 不可以。
server {
listen [::]:443 ssl http2 ipv6only=on;
listen 443 ssl http2;
server_name localhost;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
charset utf-8;
index index.php;
root /var/www/html/exploraai/public;
location ^~ /blog {
alias /var/www/html/blog;
location ~ \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.(?!well-known).* {
deny all;
}
location = /favicon.ico {
access_log off; log_not_found off;
}
location = /robots.txt {
access_log off; log_not_found off;
}
}
我尝试了不同的方法,但目前没有任何效果。
更新
对我有用的是将位置博客替换为以下位置块
location /blog {
alias /var/www/html/blog/;
try_files $uri /blog/index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}