ubuntu nginx创建多站点配制

29 篇文章 0 订阅
15 篇文章 0 订阅

安装完成nginx后,我们网站目录默认在/var/www,默认一个站点的,多个站点需要在/var/www中创建多个站点。我们一般以域名方式创建一个站点目录,然后设置站点目录权限(使用管理员账号操作),nginx配制文件默认在/etc/nginx/sites-available目录中,在此目录中创建多个站点配制文件,然后把配制文件软链接复制到/etc/nginx/sites-enabled目录中,最后重启nginx生效(域名要解析到服务器)。

创建站点目录

sudo mkdir -p /var/www/nyw.com

sudo mkdir -p /var/www/mgj.com

给站点目录设置权限(www-data:www-data 就是 Nginx 默认的用户组合用户名)

sudo chown -R www-data:www-data /var/www/nyw.com

sudo chown -R www-data:www-data /var/www/mgj.com

创建新站点配制文件,复制一份在修改吧

cp /etc/nginx/sites-available/default /etc/nginx/sites-available/mgj.com

创建软链接

ln -s /etc/nginx/sites-available/mgj.com /etc/nginx/sites-enabled/mgj.com 

修改配制文件后,重启nginx生效

如下是站点nginx配制文件 

server {
	listen 80;
	listen [::]:80;

	# SSL configuration
	#
	# listen 443 ssl default_server;
	# listen [::]:443 ssl default_server;
	#
	# Note: You should disable gzip for SSL traffic.
	# See: https://bugs.debian.org/773332
	#
	# Read up on ssl_ciphers to ensure a secure configuration.
	# See: https://bugs.debian.org/765782
	#
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	#
	# include snippets/snakeoil.conf;

	root /var/www/mgj.nyw.com;

	# Add index.php to the list if you are using PHP
	index index.html index.htm index.nginx-debian.html index.php;

	server_name mgj.nyw.com;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ =404;
	if (!-e $request_filename){
		rewrite  ^(.*)$  /index.php?s=$1  last;   break;
	}
	}

	# pass PHP scripts to FastCGI server
	
	location ~ \.php$ {
                include snippets/fastcgi-php.conf;
		# With php-fpm (or other unix sockets):
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		# With php-cgi (or other tcp sockets):
		#fastcgi_pass 127.0.0.1:9000;
	}

	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	#location ~ /\.ht {
	#	deny all;
	#}



}

在nginx配制文件中设置项目伪静态,添加如下我画出来的配制

切换服务器php版本号

sudo update-alternatives --config php

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值