【Azure 应用服务】App Service For Linux 环境中,如何修改 Nginx 配置中 server_name的默认值 example.com

本文涉及的产品
.cn 域名,1个 12个月
简介: 【Azure 应用服务】App Service For Linux 环境中,如何修改 Nginx 配置中 server_name的默认值 example.com

问题描述

在App Service for Linux环境中,部署PHP应用,使用Nginx服务器。因为PHP应用中所有静态资源的URL使用的默认域名为 https://example.com:8080 开头,所以需要在Nginx中配置域名转换,而如果使用Apache则免配置。 所以,当使用Nginx的时候,需要修改配置,在 /etc/nginx/sites-enabled/default 文件中添加 server_name : xxxxxxx.com # <对应域名>

通过添加在wwwroot根目录中添加一个测试Server Name的文件,验证发现,App Service For Linux的环境中,Server Name就是默认的example.com。

测试Server Name文件内容:

<?php 
$url = "https://" . $_SERVER['SERVER_NAME'];
echo $url;
header("location: $url");

 

解决方式

1)自定义Nginx配置文件 ,自定server_name

2)把自定义Nginx配置文件上传到 /home/site/wwwroot 文件中,可以通过FTP或者其他部署方式,也可以和PHP代码文件一起部署。

 

3)在Configuration 页面通过设置启动命令,把自定义Nginx文件复制到 /etc/nginx/sites-enabled/default/home/default 目录中,重启Nginx服务。

cp /home/site/wwwroot/default  /etc/nginx/sites-enabled/default; service nginx restart

 

 

访问站点即可得到正确的域名:

相关文章
|
11天前
|
NoSQL 关系型数据库 Redis
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
mall在linux环境下的部署(基于Docker容器),docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongodb、minio详细教程,拉取镜像、运行容器
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
|
5天前
【Azure Logic App】使用Event Hub 连接器配置 Active Directory OAuth 认证无法成功连接到中国区Event Hub的解决之法
An exception occurred while retrieving properties for Event Hub: logicapp. Error Message: 'ClientSecretCredential authentication failed: AADSTS90002: Tenant 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Che
|
20天前
|
开发框架 .NET Windows
【App Service】在App Service中配置Virtual applications and directories,访问目录中的静态文件报错404
【App Service】在App Service中配置Virtual applications and directories,访问目录中的静态文件报错404
|
20天前
|
C++
【Azure Logic App】使用Event Hub 连接器配置 Active Directory OAuth 认证无法成功连接到中国区Event Hub
【Azure Logic App】使用Event Hub 连接器配置 Active Directory OAuth 认证无法成功连接到中国区Event Hub
|
8天前
|
域名解析 负载均衡 网络协议
Linux网络接口配置不当所带来的影响
总而言之,Linux网络接口的恰当配置是保证网络稳定性、性能和安全性的基础。通过遵循最佳实践和定期维护,可以最大程度地减少配置错误带来的负面影响。
32 0
|
11天前
|
监控 安全 网络协议
快速配置Linux云服务器
快速配置Linux云服务器
|
应用服务中间件 Linux nginx
Linux系列——Nginx的安装、测试详解以及关于Nginx的常用命令介绍
Linux系列——Nginx的安装、测试详解以及关于Nginx的常用命令介绍
|
11月前
|
tengine 应用服务中间件 Linux
【Linux环境】如何在Nginx(或Tengine)服务器上安装ssl证书----介绍nginx服务器类型证书的下载与安装操作
【Linux环境】如何在Nginx(或Tengine)服务器上安装ssl证书----介绍nginx服务器类型证书的下载与安装操作
448 0
|
应用服务中间件 Linux nginx
Linux下Nginx编译安装后的开机自启动设置
Linux下Nginx编译安装后的开机自启动设置
612 0
|
应用服务中间件 Linux nginx
Linux查看nginx安装位置
查看nginx安装位置
2900 0