찾다
php教程php手册nginx 添加虚拟主机 支持php 伪静态

nginx 添加虚拟主机 支持php 伪静态

Jun 06, 2016 pm 07:45 PM
nginxphp지원하다다음에 추가가상 호스트공전

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

1添加虚拟主机

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

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

<span>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;
}</span>

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

<span>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;
}</span>

图片防盗链

 

<span>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;
}</span>

 

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

 

<span>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;
}</span>

 

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

include wordpress.conf<span>;</span>

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

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

 

 

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

WebStorm Mac 버전

WebStorm Mac 버전

유용한 JavaScript 개발 도구

ZendStudio 13.5.1 맥

ZendStudio 13.5.1 맥

강력한 PHP 통합 개발 환경

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기