首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nginx服务器多站点、多域名重定向(同端口/异端口)

问Nginx服务器多站点、多域名重定向(同端口/异端口)
EN

Stack Overflow用户
提问于 2016-08-28 08:11:16
回答 1查看 167关注 0票数 0

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

原始HTTP.CONF

代码语言:javascript
复制
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;
    }

}

原始HTTPS.CONF

代码语言:javascript
复制
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也能在port2.example.com上工作就更好了。

EN

回答 1

Stack Overflow用户

发布于 2016-09-02 07:43:44

感谢各位的收看。我最终使用了Nginx,在/etc/nginx/conf文件夹中使用多个.conf文件设置起来要快得多。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39186894

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档