我在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 作为 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 {
listen 80;
server_name abc.com www.abc.com abc.tk www.abc.tk;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location / {
root /usr/share/nginx/html
index index.html index.htm index.php;
try_files $uri $uri/;
}
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;
}
}