假设nginx和php已经安装好了
一共三个站点,默认站点使用顶级域名,其他站点使用二级域名,因为服务器上已经在使用80端口,所以统一使用880端口
主站点配置
添加如下一行,用来导入其他站点的配置文件
include /etc/nginx/conf.d/*.conf;
全部配置文件如下
[root@rocky8 ~]# cat /etc/nginx/nginx.conf|grep -Ev '^#|^$'
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
include /etc/nginx/vhost/*.conf;
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 880 default_server;
listen [::]:880 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
创建网站根目录,用来存放网站文件
[root@rocky8 ~]# mkdir /usr/share/nginx/html/web1/
[root@rocky8 ~]# mkdir /usr/share/nginx/html/web2/
创建vhost目录,用来存放其他站点的配置文件
[root@rocky8 ~]# mkdir /etc/nginx/vhost/
编辑站点一的配置文件,要访问php网站,php配置必须写
[root@rocky8 ~]# vim /etc/nginx/vhost/web1.conf
server {
listen 880; # 监听端口
server_name web1.chunjiemail.com; # 站点域名
root /usr/share/nginx/html/web1/; # 站点根目录
index index.html index.htm index.php; # 默认导航页
# PHP配置
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/www.sock; #后面跟php-fpm的sock,有些版本也可以跟ip+9000端口号
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
}
站点二的配置文件
[root@rocky8 ~]# vim /etc/nginx/vhost/web2.conf
server {
listen 880; # 监听端口
server_name web2.chunjiemail.com; # 站点域名
root /usr/share/nginx/html/web2/; # 站点根目录
index index.html index.htm index.php; # 默认导航页
location / {
# WordPress固定链接URL重写
if (!-e $request_filename) {
rewrite (.*) /index.php;
}
}
# PHP配置
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
}
然后重启nginx服务,访问网站
发表评论