请教nginx 多个 server 怎么配置

请教nginx 多个 server 怎么配置,第1张

在/etc/nginx/下建一个文件夹放站点配置文件,如example 地址是:/etc/nginx/example

在example文件夹里建多个站点的conf文件,如:example1.conf , example2.conf

每个conf配置文件如下,可修改server_name 和 location地址设置多个站点。

server {

listen 80

server_name michaelaschmidt.com www.michaelaschmidt.com

access_log /var/www/access_michaelaschmidt.log

location / {

root /var/www/michaelaschmidt.com

index index.php index.html index.htm

}

error_page 500 502 503 504 /50x.html

location = /50x.html {

root /usr/share/nginx/html

}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

location ~ /.php$ {

fastcgi_pass 127.0.0.1:9000

fastcgi_index index.php

fastcgi_param SCRIPT_FILENAME /var/www/michaelaschmidt.com/$fastcgi_script_name

includefastcgi_params

}

location ~ //.ht {

deny all

}

}

保存后在/etc/nginx/nginx.conf里面的http{} 里面加入:

include /etc/nginx/example/*.conf #将example文件夹下的所有.conf包含入nginx.conf配置文件

最后记得重启nginx:

/etc/init.d/nginx restart

亲,不需要用http包住,nginx的server块可以用来配置多个虚拟主机,每个虚拟主机可以有自己的域名、端口号和根目录,可以把不同的网站放在不同的server块中,以实现多个虚拟主机的配置。此外,nginx还支持负载均衡,可以将多台服务器上的服务器负载均衡到一台服务器上,以提高网站的访问速度和稳定性。另外,nginx还支持反向代理,可以将外部请求转发到内部服务器,以实现安全隔离。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11700568.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存