Nginx服务器多站点和域重定向(在同一端口/不同端口)

时间:2016-08-28 00:11:16

标签: http nginx https server

我正在尝试在同一个nginx服务器上托管多个不相关的网站。如何编辑http.conf和https.conf文件以使其正常工作?

ORIGINAL HTTP.CONF

server {
    listen 2333;
    server_name port1.example.com;
    rewrite ^/(.\*) http://port1.example.com/$1 permanent;
    root /var/www/html;
    index index.php index.html;

    # set max upload size
    client_max_body_size 2G;
    fastcgi_buffers 64 4K;

    access_log /var/log/nginx/http_access.log combined;
    error_log /var/log/nginx/http_error.log;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }   

    location ~ \.php$
    {
        try_files      $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~* \.(htaccess|htpasswd) {
        deny all;
    }

    # set long EXPIRES header on static assets
    location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
        expires 30d;
        access_log off;
    }

}

ORIGINAL HTTPS.CONF

server {
    listen 4433 ssl default_server;
    server_name _;

    ssl_certificate /etc/nginx/ssl/port2.example.com.crt;
    ssl_certificate_key /etc/nginx/ssl/port2.example.com.key;

    root /usr/share/nginx/html;
    index index.php index.html;

    # set max upload size
    client_max_body_size 2G;
    fastcgi_buffers 64 4K;

    access_log /var/log/nginx/https_access.log combined;
    error_log /var/log/nginx/https_error.log;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }   

    location ~ \.php$
    {
        try_files      $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~* \.(htaccess|htpasswd) {
        deny all;
    }

    # set long EXPIRES header on static assets
    location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
        expires 30d;
        access_log off;
    }

}

我的端口4433显然在SSL上。如何让端口2333仅在port1.example。com和端口4433上工作,仅适用于port2.example.com如果2333也可以在SSL上提供,那就更好了。

1 个答案:

答案 0 :(得分:0)

感谢大家观看。我最终使用了Nginx,使用/etc/nginx/conf文件夹中的多个.conf文件设置得更快。