Следует ли мне использовать моментальный снимок, том, изображение или VPS для перемещения веб-приложений из одного экземпляра в другой

У меня есть практические знания о том, что такое снимок, том, VPS и изображение по отдельности. В настоящее время у меня есть по одному экземпляру каждого из них, а также зарезервированный экземпляр и экземпляр ec2. Я пытаюсь переместить свои приложения из ec2 в зарезервированный, не затрагивая мои микросервисы S3, SES и Route53. com / thing будет перенаправлен на http: // example / thing / , что вызовет сбой запроса.

Вот как выглядит мой nginx.conf:

#user  nobody;
worker_processes  1;

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

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    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"';

    log_format logstash_json '{ "@timestamp": "$time_iso8601", '
                          '"@fields": { '
                          '"remote_addr": "$remote_addr", '
                          '"remote_user": "$remote_user", '
                          '"request": "$request", '
                          '"status": "$status", '
                          '"body_bytes_sent": "$body_bytes_sent", '
                          '"request_time": "$request_time", '
                          '"request_method": "$request_method", '
                          '"http_referrer": "$http_referer", '
                          '"http_user_agent": "$http_user_agent" } }';

    access_log  /var/log/access.log  logstash_json;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8080;            # Port to listen on
        server_name  localhost;       # Servername
        client_max_body_size 0;       # Max upload size
        chunked_transfer_encoding on; # Support for chunked transfer (upload)
        port_in_redirect off;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

        #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$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # 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 ssl;
    #    server_name  localhost;

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

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    #include servers/*;
}
1
задан 2 April 2018 в 21:06
1 ответ

По умолчанию nginx выдает абсолютный URL-адрес в ответе 3xx, который включает схему, используемую для подключения к серверу. Ваш сервер на порту 8080 подключен к более http , так что это схема, которая появляется в ответе 3xx.

Начиная с версии 1.11.8, nginx может быть настроен для выдачи вместо этого относительный URL-адрес, который удаляет схему и имя хоста из URL.

absolute_redirect off;

Подробнее см. этот документ .


Если вы используете старую версию nginx ( и его обновление не является вариантом ) вы можете изменить поведение по умолчанию, используя явный оператор if ... return .

Существующая конфигурация кажется довольно простой:

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

Существует несколько крайних случаев, поэтому решение может стать довольно сложным, но что-то вроде этого может сработать для вас:

root html;

location ~ /$ {
    try_files "${uri}index.html" "${uri}index.htm" =404;
}
location / {
    try_files $uri @rewrite;
}
location @rewrite {
    if (-d $request_filename) { 
        return https://$host$uri/$is_args$args; 
    }
}
4
ответ дан 3 December 2019 в 17:34

Теги

Похожие вопросы