
php
nginxserver { listen 80; server_name example.com www.example.com; root /path/to/example.com/html; index index.html; location / { try_files $uri $uri/ /index.html; } location ~ .php$ { include fastcgi_params; fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }}以上配置会将所有请求都转发到example.com,并且如果存在.php扩展名的请求,则使用FastCGI方式处理。如果要实现其他域名进行跳转,只需在"location"指令中添加相应的域名即可。例如,如果要将www.example.com的请求转发到example.com,可以添加以下配置:nginxserver { listen 80; server_name example.com www.example.com; root /path/to/example.com/html; index index.html; location / { try_files $uri $uri/ /index.html; } location ~ .php$ { include fastcgi_params; fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }}server { listen 80; server_name www.example.com; root /path/to/example.com/html; index index.html; location / { try_files $uri $uri/ /index.html; }}以上配置会将www.example.com的请求直接转发到example.com的根目录下。这样就实现了不同域名的跳转功能。Copyright © 2025 IZhiDa.com All Rights Reserved.
知答 版权所有 粤ICP备2023042255号