nginx - 多个站点的 nginx 配置一个 ip 地址和一个服务器
问题描述
nginx 多个网站在同一个端口和一个 ip 地址
例如我的 ip 192.167.10.2
我们想在相同的 ip nginx/html 上运行站点包含两个项目,如下所示
1:项目1 2:项目2
我们在 ip :192.167.10.2 上运行默认 project1,第二个项目像 192.167.10.2/project2 一样运行
如何在 nginx 配置文件中进行配置
解决方案
这是一个简单的例子。你可以试试
第一个配置:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/mywebsite1;
index index.php index.html index.htm;
server_name mywebsite1.de www.mywebsite1.de;
location / {
try_files $uri/ /index.php?$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/mywebsite1;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
第二个配置:
server {
listen 80;
listen [::]:80 //@here Be carefull , only one default
root /var/www/mywebsite2;
index index.php index.html index.htm;
server_name mywebsite1.de www.mywebsite1.de;
location / {
try_files $uri/ /index.php?$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/mywebsite1;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
不要忘记重新启动服务器。
推荐阅读
- python - 如何在 django 中获取外键字段值?
- java - 如何在 Android Studio 中更改 ArrayList 元素的颜色
- javascript - 错误:TypeError:无法读取 AthenaExpress.query 中未定义的属性“流”
- excel - Excel VBA 添加日期小于或等于动态今天日期的数据验证
- autodesk - Autodesk Forge [GET] /activities/:id 始终返回 null
- ios - Moya 不会只显示响应正文
- docker - 我如何知道 `docker pull` 将获取多少数据?
- math - 如何获得用户给出的较少数量的输入?
- python - Pytest-django 事务未物理提交到数据库
- c# - ASP.NET Core MVC 已将文件上传到某些类别