美文网首页程序员
nginx配置虚拟域名

nginx配置虚拟域名

作者: White夏天baby | 来源:发表于2020-08-14 15:00 被阅读0次

1.进入虚拟主机配置文件夹

cd /etc/nginx/conf.d

2. 新建一个站点

vim test.actself.me.conf

3.内容如下:

server {

listen 80;

server_name test.actself.me;

root /var/www/test.actself.me;

index index.html;

location \ {

}

location ~ \.php$ {

fastcgi_pass  127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

include        fastcgi_params;

}

}

以上配置在上传TP5项目时出错,以下为新的配置

server {

listen 80;

server_name www.tp.com;

set $root_path '/var/www/www.tp.com/public';

root $root_path;

index index.php index.html index.htm;

try_files $uri $uri/ @rewrite;

location @rewrite {

if (!-e $request_filename) {

rewrite  ^(.*)$  /index.php?s=/$1  last;

}

}

location ~ \.php {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index /index.php;

fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {

root $root_path;

}

location ~ /\.ht {

deny all;

}

}

4.根据上图的root,进入/var/www/test.actself.me文件夹创建index.php文件

5.在index.php文件中写入php代码

6.在自己主机上找到hosts文件

7.在最底部,填写服务器ip地址,与虚拟域名 

192.xxx.xxx.xx test.actself.me

8.重启服务器

9.打开页面代码正常运行

————————————————

文章参考:LNMP环境搭建辅助资料

https://class.imooc.com/course/631

相关文章

  • Nginx进阶

    nginx 日志文件详解 监听 nginx 虚拟机配置 基于域名的虚拟主机

  • Mac下安装lnmp

    安装mysql5.6 安装nginx 安装php 修改nginx配置 是其能运行php 配置虚拟域名

  • Nginx——虚拟主机配置

    基于域名的虚拟主机 基于端口的虚拟主机 基于IP的虚拟主机nginx的主配置文件/etc/nginx/nginx....

  • nginx2-路由

    1.nginx管理虚拟主机 基于域名虚拟主机配置 基于端口虚拟主机配置 基于ip虚拟主机配置 2.Location...

  • 02_nginx虚拟主机、日志管理

    虚拟主机 Nginx配置段 conf/nginx.conf 基于域名的虚拟主机在http{}中添加 上面的root...

  • Nginx 虚拟主机

    什么是虚拟主机 Nginx 配置文件的结构 基于 IP 的虚拟主机配置 基于端口的虚拟主机配置 基于域名的虚拟主机...

  • Nginx 配置虚拟域名

    环境 window + phpstudy 打开nginx.conf把server复制一份,截图没复制完,请注意...

  • nginx配置虚拟域名

    修改host host路径:C:\Windows\System32\drivers\etc\hosts 保存退出 ...

  • nginx配置虚拟域名

    1.进入虚拟主机配置文件夹 cd /etc/nginx/conf.d 2. 新建一个站点 vim test.act...

  • Nginx虚拟机

    nginx 虚拟机配置 基于域名的虚拟主机 vim /etc/hosts10.0.122.156 www.111....

网友评论

    本文标题:nginx配置虚拟域名

    本文链接:https://www.haomeiwen.com/subject/tregdktx.html