V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Gauin
V2EX  ›  WordPress

前端Nginx 后端Apache,Wordpress如何开启伪静态?

  •  
  •   Gauin · 2012-10-30 09:26:08 +08:00 · 6106 次点击
    这是一个创建于 4198 天前的主题,其中的信息可能已经有所发展或是发生改变。
    BudgetVM VPS空间 Linux主机。

    同事帮忙配置了伪静态,但没弄好。我折腾了一晚上,没搞定。有大牛会弄的吗?分享个方法,我让同事弄一下。

    http://www.gauin.com/ 博客停了好几天了,伪静态还没弄好 求助
    第 1 条附言  ·  2013-03-15 08:22:30 +08:00
    不得已 用军哥的LNMP一键安装包配置好了 目前博客运行正常

    http://www.gauin.com/ 可以访问看看
    13 条回复    2014-11-06 22:31:48 +08:00
    santa
        1
    santa  
       2012-10-30 10:00:25 +08:00
    后端Apache的话应该直接用.htaccess解决,nginix什么都不用做才对吧
    qiuai
        2
    qiuai  
       2012-10-30 10:13:21 +08:00
    @santa 是的
    anyforever
        3
    anyforever  
       2012-10-30 10:22:20 +08:00   ❤️ 1
    楼上两位的正解,应该在Apache里配置伪静态.
    你找Apache下的配置方法就Ok了。
    Gauin
        4
    Gauin  
    OP
       2012-10-30 13:13:42 +08:00
    @anyforever 我试了 没弄好。Gtalk能给我下吗
    chairo
        5
    chairo  
       2012-10-30 13:19:19 +08:00
    添加.htaccess,且删除nginx里的伪静态规则
    Gauin
        6
    Gauin  
    OP
       2012-10-30 13:22:11 +08:00
    @chairo 下面是Nginx的 conf文件配置。删掉那些?

    user daemon;
    worker_processes 8;

    #error_log logs/error.log;
    #error_log logs/error.log notice;
    #error_log logs/error.log info;

    pid logs/nginx.pid;
    google_perftools_profiles /var/tmp/tcmalloc;
    worker_rlimit_nofile 51200;


    events {
    use epoll;
    worker_connections 51200;
    }


    http {
    server_tokens off;
    include mime.types;
    default_type application/octet-stream;

    #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    # '$status $body_bytes_sent "$http_referer" '
    # '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log logs/access.log main;

    sendfile on;
    tcp_nopush on;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;

    #keepalive_timeout 0;
    keepalive_timeout 120;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    include vhost/*.conf;

    server {
    listen 80;
    server_name www.gauin.com;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
    root /usr/local/apache2/htdocs/wordpress/;
    index index.html index.htm index.php;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    location ~ \.(php|php5)?$ {
    proxy_pass http://127.0.0.1:81;
    }
    include proxy.conf;

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    # root html;
    # fastcgi_pass 127.0.0.1:9000;
    # fastcgi_index index.php;
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    # include fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    # deny all;
    #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    # listen 8000;
    # listen somename:8080;
    # server_name somename alias another.alias;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}


    # HTTPS server
    #
    #server {
    # listen 443;
    # server_name localhost;

    # ssl on;
    # ssl_certificate cert.pem;
    # ssl_certificate_key cert.key;

    # ssl_session_timeout 5m;

    # ssl_protocols SSLv2 SSLv3 TLSv1;
    # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    # ssl_prefer_server_ciphers on;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}

    }
    chairo
        7
    chairo  
       2012-10-30 14:05:48 +08:00
    @Gauin 试试server段用这个写法,原配置文件保留备份,如果下边这段不能用建议恢复成你的那个文件

    server {
    listen 80;
    server_name www.gauin.com;
    index index.html index.htm index.php;
    root /usr/local/apache2/htdocs/wordpress/;

    location / {
    try_files $uri @apache;
    }

    location @apache {
    internal;
    proxy_pass http://127.0.0.1:81;
    include proxy.conf;
    }

    location ~ .*\.(php|php5)?$ {
    proxy_pass http://127.0.0.1:81;
    include proxy.conf;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }

    }
    ajoop
        8
    ajoop  
       2012-10-30 14:09:59 +08:00
    如果就一个博客的话,没必要后端用apache了,直接LNMP就可以了,占用资源还少,如果用军哥LNMP一键安装包的话,添加网站时候会提示你是否设置rewrite的,其中就有WP伪静态的选项,根本不用自己去写。
    Gauin
        9
    Gauin  
    OP
       2012-10-30 23:46:32 +08:00
    @ajoop 同事是运维工程师 然后后 说前端Nginx 后端Apache服务器性能碉堡啊 你懂的 我就同意了

    工程师都爱折腾啊
    Gauin
        10
    Gauin  
    OP
       2012-10-30 23:55:21 +08:00
    @chairo

    Gtalk给我帮忙弄一下好吗?我会说我不信你吗? 博客挂了好几天了 就为这事啊 就为这事儿
    TONYHEAD
        11
    TONYHEAD  
       2012-10-31 14:48:19 +08:00
    有插件的,搜索下nginx
    ybf1220
        12
    ybf1220  
       2012-10-31 15:00:44 +08:00
    其实前端 nginx 后端 apache 和直接 nginx+php-fpm 相差不是很大。在20%之内。再说 apache2 对 内存是占用很大的。而且容易跨站。 只是对付 php 的话 用php-fpm 管理 fastcgi,这样执行足以,要性能好,可以再安装缓存插件 ,比如 eacc ,memcache,APC,xcache 等,轻量级我比较推崇,虽然 apache2 现在还是web服务器的老大。
    vowmmm
        13
    vowmmm  
       2014-11-06 22:31:48 +08:00
    @chairo 非常感谢。搞了好久,试来试去,大家都说,“直接用.htaccess解决,nginix什么都不用做”。最终发现,不是apache的.htaccess的问题。加上

    location / {
    try_files $uri @apache ;
    }

    location @apache {
    internal;
    proxy_pass http://127.0.0.1:81;
    include proxy.conf;
    }

    就可以了。我又查了一下@apache的意思,没找到。
    能说说@apache的意思吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5781 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 02:44 · PVG 10:44 · LAX 19:44 · JFK 22:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.