1添加虚拟主机

进入 /usr/local/nginx/conf/vhost 目录, 创建虚拟主机配置文件 demo.neoease.com.conf ({域名}.conf).

2. 打开配置文件, 添加服务如下:

server {
listen 80;
server_name demo.neoease.com;
index index.html index.htm index.php;
root /var/www/demo_neoease_com; log_format demo.neoease.com '$remote_addr - $remote_user [$time_local] $request'
'$status $body_bytes_sent $http_referer '
'$http_user_agent $http_x_forwarded_for';
access_log /var/log/demo.neoease.com.log demo.neoease.com;
}

3. 打开 Nginx 配置文件 /usr/local/nginx/conf/nginx.conf, 在 http 范围引入虚拟主机配置文件如下:

include vhost/*.conf;

这句也可以直接包含虚拟主机文件的地址 例如: /usr/local/nginx/conf/vhost/demo.neoease.com.conf

4.重启apache --nginx

service nginx restart

支持php

server {
listen 80;
server_name demo.neoease.com;
index index.html index.htm index.php;
root /var/www/demo_neoease_com; location ~ .*\.(php|php5)?$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
} log_format demo.neoease.com '$remote_addr - $remote_user [$time_local] $request'
'$status $body_bytes_sent $http_referer '
'$http_user_agent $http_x_forwarded_for';
access_log /var/log/demo.neoease.com.log demo.neoease.com;
}

图片防盗链

server {
listen 80;
server_name demo.neoease.com;
index index.html index.htm index.php;
root /var/www/demo_neoease_com; # 这里为图片添加为期 1 年的过期时间, 并且禁止 Google, 百度和本站之外的网站引用图片
location ~ .*\.(ico|jpg|jpeg|png|gif)$ {
expires 1y;
valid_referers none blocked demo.neoease.com *.google.com *.baidu.com;
if ($invalid_referer) {
return 404;
}
} log_format demo.neoease.com '$remote_addr - $remote_user [$time_local] $request'
'$status $body_bytes_sent $http_referer '
'$http_user_agent $http_x_forwarded_for';
access_log /var/log/demo.neoease.com.log demo.neoease.com;
}

WordPress 伪静态配置---------------如果将 WordPress 的链接结构设定为 /%postname%/, /%postname%.html 等格式时, 需要 rewrite URL, WordPress 提供 Apache 的 .htaccess 修改建议, 但没告知 Nginx 该如何修改. 我们可以将 WordPress 的虚拟主机配置修改如下:

server {
listen 80;
server_name demo.neoease.com;
index index.html index.htm index.php;
root /var/www/demo_neoease_com; location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent; location ~ .*\.(php|php5)?$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
} log_format demo.neoease.com '$remote_addr - $remote_user [$time_local] $request'
'$status $body_bytes_sent $http_referer '
'$http_user_agent $http_x_forwarded_for';
access_log /var/log/demo.neoease.com.log demo.neoease.com;
}

LNMP 套件在提供了 WordPress 为静态配置文件 /usr/local/nginx/conf/wordpress.conf, 在虚拟主机配置的 server 范围引用如下即可.

include wordpress.conf;

如果你使用 LNMP 套件, 进入 WordPress 后台发现会出现 404 页面, wp-admin 后面缺少了斜杆 /, 请在 wordpress.conf 最后添加以下语句:

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

nginx 添加虚拟主机 支持php 伪静态的更多相关文章

  1. centos7 安装 iRedmail 后 给nginx添加虚拟主机

    iRedmail安装参考官方文档和 https://ywnz.com/linuxyffq/4563.html 准备工作 更新操作系统 yum update -y 安装必要组件 yum install ...

  2. nginx 配置虚拟主机(支持php)

    配置步骤: 1.在nginx安装目录下,找到nginx.conf所在文件夹,新建vhost文件夹 2.在nginx.conf http{} 末端加入 include vhost/*.conf; 3.进 ...

  3. LNMP一键安装包添加虚拟主机、删除虚拟主机及如何使用伪静态

    本文主要介绍LNMP一键安装包添加虚拟主机.删除虚拟主机及如何使用伪静态. 一.添加虚拟主机通俗点就是在VPS/服务商上添加一个网站(域名). 需要执行如下命令:/root/vhost.sh 执行后会 ...

  4. [转] linux学习第四十四篇:Nginx安装,Nginx默认虚拟主机,Nginx域名重定向

    Nginx安装 进入存放源码包的目录: cd /usr/local/src 下载源码包: wget http://nginx.org/download/nginx-1.12.1.tar.gz 解压: ...

  5. nginx配置虚拟主机vhost的方法详解

    Nginx vhost配置,可实现基于ip.端口号.servername的虚拟主机,同时可避免直接修改主配置文件.在nginx下配置虚拟主机vhost非常方便.这篇文章主要介绍了nginx配置虚拟主机 ...

  6. Nginx中虚拟主机配置

    一.Nginx中虚拟主机配置 1.基于域名的虚拟主机配置 1.修改宿主机的hosts文件(系统盘/windows/system32/driver/etc/HOSTS) linux : vim /etc ...

  7. apache添加虚拟主机(windows下)

    1.打开Apache的目录下的  D:\Web\Apache\conf\httpd.conf 允许虚拟,启动虚拟配置文件 2.配置虚拟主机 打开 D:\Web\Apache\conf\extra\ht ...

  8. nginx配置虚拟主机、反向代理和负载均衡

    为了实现这个功能,需要修改nginx的配置文件,将nginx.conf清理一下,使结构更清晰. worker_processes ; events { worker_connections ; } h ...

  9. nginx多虚拟主机优先级location匹配规则及tryfiles的使用

    nginx多虚拟主机优先级location匹配规则及tryfiles的使用 .相同server_name多个虚拟主机优先级访问 .location匹配优先级 .try_files使用 .nginx的a ...

随机推荐

  1. 使你的IT职业生涯更上一层楼de14条建议

    摘要:升值为企业IT部门的领导者,是大部分IT技术人员职业生涯的最终追求.但从一般大众中脱颖而出,并非易事.仅仅把本职工作干好远远不够,还需要IT技术人员展示出投身于技术发展的奉献精神及伴随技术发展而 ...

  2. 爬虫、网页分析解析辅助工具 Xpath-helper

    每一个写爬虫.或者是做网页分析的人,相信都会因为在定位.获取xpath路径上花费大量的时间,甚至有时候当爬虫框架成熟之后,基本上主要的时间都花费在了页面的解析上.在没有这些辅助工具的日子里,我们只能通 ...

  3. 【CentOS7】CentOS 7 安装 MySQL

    转自:http://www.centoscn.com/mysql/2016/0315/6844.html 环境 CentOS 7.1 (64-bit system) MySQL 5.6.24 Cent ...

  4. 阿里云数据库配置学习笔记(二):下载并配置MySQL数据库

    参考资料:阿里云官方文档 2018-02-20 一.MySQL数据库的下载 在Ubuntu环境下安装MySQL数据库十分简单 在命令行中输入 sudo apt-get update(更新软件源,预防出 ...

  5. Spring Data Redis —— 快速入门

    环境要求:Redis 2.6及以上,javase 8.0及以上: 一.Spring Data Redis 介绍 Spring-data-redis是spring的一部分,提供了在srping应用中通过 ...

  6. BZOJ3884(SummerTrainingDay04-C 欧拉定理)

    上帝与集合的正确用法 根据一些书上的记载,上帝的一次失败的创世经历是这样的: 第一天,  上帝创造了一个世界的基本元素,称做“元”. 第二天,  上帝创造了一个新的元素,称作“α”.“α”被定义为“元 ...

  7. POJ2387(KB4-A)

    Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 54716   Accepted ...

  8. 【读书笔记】iOS-网络-三种错误

    一,操作系统错误. iOS人机界面指南中,Apple建议不要过度使用AlertViews,因为这会破坏设备的使用感受. 操作系统错误: 1,没有网络. 2,无法路由到目标主机. 3,没用应和监听目标端 ...

  9. 安装vs2008出现MSI returned error code 1603的错误的解决

    作者:朱金灿 来源:http://blog.csdn.net/clever101 在win7 64位旗舰版上安装vs2008 ,一直停留在下面页面: 最后错误日志是: [12/12/16,15:39: ...

  10. SAP FI/CO 基本概念

    每一个SAP从业者都对这些概念不陌生,理解透了这些概念,对SAP的业务体系构架才能有明确地认识. 1.集团(client)的概念:是SAP中的最高等级:每一个集团建立主数据库. 2.公司(Compan ...