nginx 添加虚拟主机 支持php 伪静态
2013-07-12 09:34
597 查看
1添加虚拟主机
进入 /usr/local/nginx/conf/vhost 目录, 创建虚拟主机配置文件 demo.neoease.com.conf ({域名}.conf).
2. 打开配置文件, 添加服务如下:
3. 打开 Nginx 配置文件 /usr/local/nginx/conf/nginx.conf, 在
这句也可以直接包含虚拟主机文件的地址 例如: /usr/local/nginx/conf/vhost/demo.neoease.com.conf
4.重启apache --nginx
支持php
图片防盗链
WordPress 伪静态配置---------------如果将 WordPress 的链接结构设定为
LNMP 套件在提供了 WordPress 为静态配置文件 /usr/local/nginx/conf/wordpress.conf, 在虚拟主机配置的 server 范围引用如下即可.
如果你使用 LNMP 套件, 进入 WordPress 后台发现会出现 404 页面, wp-admin 后面缺少了斜杆
进入 /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; |
/, 请在 wordpress.conf 最后添加以下语句:
rewrite /wp-admin$ $scheme://$host$uri/ permanent; |
相关文章推荐
- nginx (lnmp)配置支持php,虚拟主机
- Nginx 安装笔记(含PHP支持、虚拟主机、反向代理负载均衡)
- Nginx安装简记(含PHP支持、虚拟主机、反向代理负载均衡)
- Nginx安装配置(含PHP支持、虚拟主机、反向代理负载均衡)
- Nginx 虚拟主机 配置 支持独立urlwrite 文件, php-fpm独立用户和php....
- Nginx 安装笔记(含PHP支持、虚拟主机、反向代理负载均衡)
- Nginx虚拟主机配置 + 虚拟主机支持PHP
- Nginx多站点虚拟主机实现单独启动停止php-fpm、单独控制权限设置
- nginx之添加虚拟主机和web账号访问
- 网站子目录绑定二级域名 php虚拟主机可以通过添加个.htaccess文件实现绑定
- nginx“虚拟目录”不支持php的解决办法
- Nginx添加虚拟主机
- [Linux] Ubuntu_9.04_server安装nginx+php(fastcgi)+nginx虚拟主机配置格式
- nginx 配置虚拟主机访问PHP文件 502错误的解决方法
- nginx默认虚拟主机,用户认证,域名重定向,日志,静态文件不记录日志,防盗链,访问控制,php解析
- Nginx 虚拟主机下支持Pathinfo并隐藏入口文件的完整配置
- Nginx发布Alias虚拟目录及PHP支持配置方法
- LiteSpeed添加虚拟主机+支持htaccess图文教程
- php管理nginx虚拟主机shell脚本
- nginx 配置虚拟主机访问PHP文件 502错误的解决方法