【发布时间】:2019-01-11 15:48:45
【问题描述】:
我在 AWS 上配置了 nginx 服务器请求流程,如下所示: 以下代码片段是 nginx 内部的自定义 conf 文件
server {
listen 80;
server_name abc.tk www.abc.tk;
# note that these lines are originally from the "location /" block
#root /usr/share/nginx/html;
#index index.php index.html index.htm;
#location / {
#try_files $uri $uri/ =404;
#}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
最初,我有一个域(如上),它工作正常,但现在我想对另一个域执行相同的重定向到同一个根文件夹。顺便说一句,我这里没有提到根文件夹,它来自 nginx.conf。我尝试了不同的方法来阅读在线资源,但没有取得任何成功。 以下是我现在正在尝试的,但它不起作用。给我 521:Web 服务器关闭错误。另外,我在这两个域中都使用了 cloudflare for ssl。
server {
listen 80;
server_name abc.com www.abc.com abc.tk www.abc.tk;
# note that these lines are originally from the "location /" block
#root /usr/share/nginx/html;
#index index.php index.html index.htm;
#location / {
#try_files $uri $uri/ =404;
#}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
快速帮助将不胜感激。提前致谢!
【问题讨论】:
-
你想将用户重定向到一个特定的域还是仅仅为 server_name 中列出的所有域提供页面?
-
是的......我想要后一个,为 server_name 中列出的所有域提供页面
-
我也在服务器名称中尝试了正则表达式,如 abc.* www.abc.* 但结果相同
标签: nginx