nginx 添加虚拟主机 支持php 伪静态
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 伪静态的更多相关文章
- centos7 安装 iRedmail 后 给nginx添加虚拟主机
iRedmail安装参考官方文档和 https://ywnz.com/linuxyffq/4563.html 准备工作 更新操作系统 yum update -y 安装必要组件 yum install ...
- nginx 配置虚拟主机(支持php)
配置步骤: 1.在nginx安装目录下,找到nginx.conf所在文件夹,新建vhost文件夹 2.在nginx.conf http{} 末端加入 include vhost/*.conf; 3.进 ...
- LNMP一键安装包添加虚拟主机、删除虚拟主机及如何使用伪静态
本文主要介绍LNMP一键安装包添加虚拟主机.删除虚拟主机及如何使用伪静态. 一.添加虚拟主机通俗点就是在VPS/服务商上添加一个网站(域名). 需要执行如下命令:/root/vhost.sh 执行后会 ...
- [转] linux学习第四十四篇:Nginx安装,Nginx默认虚拟主机,Nginx域名重定向
Nginx安装 进入存放源码包的目录: cd /usr/local/src 下载源码包: wget http://nginx.org/download/nginx-1.12.1.tar.gz 解压: ...
- nginx配置虚拟主机vhost的方法详解
Nginx vhost配置,可实现基于ip.端口号.servername的虚拟主机,同时可避免直接修改主配置文件.在nginx下配置虚拟主机vhost非常方便.这篇文章主要介绍了nginx配置虚拟主机 ...
- Nginx中虚拟主机配置
一.Nginx中虚拟主机配置 1.基于域名的虚拟主机配置 1.修改宿主机的hosts文件(系统盘/windows/system32/driver/etc/HOSTS) linux : vim /etc ...
- apache添加虚拟主机(windows下)
1.打开Apache的目录下的 D:\Web\Apache\conf\httpd.conf 允许虚拟,启动虚拟配置文件 2.配置虚拟主机 打开 D:\Web\Apache\conf\extra\ht ...
- nginx配置虚拟主机、反向代理和负载均衡
为了实现这个功能,需要修改nginx的配置文件,将nginx.conf清理一下,使结构更清晰. worker_processes ; events { worker_connections ; } h ...
- nginx多虚拟主机优先级location匹配规则及tryfiles的使用
nginx多虚拟主机优先级location匹配规则及tryfiles的使用 .相同server_name多个虚拟主机优先级访问 .location匹配优先级 .try_files使用 .nginx的a ...
随机推荐
- PHP缓存库phpFastCache
phpFastCache是一个开源的PHP缓存库,只提供一个简单的PHP文件,可方便集成到已有项目,支持多种缓存方法,包括:apc, memcache, memcached, wincache, fi ...
- vector向量容器(常用的使用方法总结)
关于STL中vector容器的学习,编译运行后边看代码,边看执行结果效果更佳,还是想说看别人的代码一百遍,不如自己动手写一遍. vector向量容器不但能像数组一样对元素进行随机访问,还能随时在尾部插 ...
- Python时间系统
Python的time和datetime模块提供了时间日期工具, python中的时间有4种表示方式: datetime obj time obj/tuple posix timestamp time ...
- UIView动画上
主要参考:http://blog.csdn.net/huifeidexin_1/article/details/7597868 http://www.2cto.com/kf/201409/33566 ...
- [转]SQL Server 中WITH (NOLOCK)浅析
本文转自:https://www.cnblogs.com/kerrycode/p/3946268.html 概念介绍 开发人员喜欢在SQL脚本中使用WITH(NOLOCK), WITH(NOLOCK) ...
- Redis集合操作
Redis的集合以无序的形式存储多个各不相同的元素 (常用的集合命令) SADD : SADD key-name item [item ...]----------将一个或多个元素添加到集合里,并返回 ...
- smtp的host地址
SMTP是SIMPLE MAIL TRANSFER PROTOCOL的缩写,一般的发信软件,如Outlook Express.FoxMail.Eudora都是使用这个协议进行发信的.SMTP Host ...
- UML,构件图与部署图
一.构件图概述 1.概念 用来显示一组构件之间的组织及其依赖关系 2.基本元素 (1)构件:定义了良好接口的物理实现单元. ● 配置构件:形成可执行文件的基础,如:动态链接库(DLL).ActiveX ...
- Java - 线程让步和休眠
Java多线程系列--“基础篇”06之 线程让步 概要 本章,会对Thread中的线程让步方法yield()进行介绍.涉及到的内容包括:1. yield()介绍2. yield()示例3. yield ...
- linux_shell_数组
shell数组类似与C语言,数组下标由0开始编号.想要获取数组中的元素要利用下标. 1.首先定义数组 在shell中,用括号来表示数组,数组元素用“空格”符号分割开.列: name=("d& ...