nginx配置

2016-04-28 10:09  1270人阅读  评论 (0)
Tags: nginx

框架url重写

location / {
    index  index.html index.htm index.php;

    if (!-e $request_filename) {
        rewrite .* /index.php last;
    }
}

非www跳转到www

if ($host != 'www.dotcoo.com') {
    rewrite (.*) http://www.dotcoo.com/$1 permanent;
}

http跳转到https

if ($scheme != https) {
    rewrite (.*) https://www.dotcoo.com$1 permanent;
}

nginx代理

location / {
    proxy_pass         http://127.0.0.1:7070;
    proxy_set_header   Host            $http_host;
    proxy_set_header   X-Real-IP       $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
}

模板

server {
    listen 80;
    listen 443 ssl;
    ssl_certificate     /data/www/key/www.dotcoo.com.chained.crt;
    ssl_certificate_key /data/www/key/www.dotcoo.com.key;
    server_name dotcoo.com www.dotcoo.com;
    index index.html index.htm index.php default.html default.htm default.php;
    root  /data/www/www.dotcoo.com/public;

    if ($host != 'www.dotcoo.com') {
        rewrite ^/(.*)$ http://www.dotcoo.com/$1 permanent;
    }

    if ($scheme != 'https') {
        rewrite ^/(.*)$ https://www.dotcoo.com/$1 permanent;
    }

    location / {
        proxy_pass         http://127.0.0.1:7070;
        proxy_set_header   Host            $host;
        proxy_set_header   X-Real-IP       $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}