一次web系统的nginx配置恢复

前言:组里有一个小伙子,为了升级nodejs,安装各种库,把系统给搞崩溃了,无法登录。找运维人员也不行,最后的解决办法换一台机器。幸好原来只有一块盘,所以数据还在。

 

$ mv a/ b/ c/ .../ -t old_machine_bak # 把之前的数据都移到

第一步:找nginx配置

$ find old_machine_bak/ -name nginx

结果:

old_machine_bak/usr/sbin/nginx

old_machine_bak/usr/share/doc/nginx
old_machine_bak/usr/share/nginx
old_machine_bak/etc/default/nginx
old_machine_bak/etc/nginx
old_machine_bak/etc/logrotate.d/nginx
old_machine_bak/etc/init.d/nginx
old_machine_bak/etc/ufw/applications.d/nginx
old_machine_bak/var/log/nginx
old_machine_bak/var/lib/nginx
old_machine_bak/var/lib/docker/overlay2/4

 

看目录,nginx配置路径应该在:

$ /data/old_machine_bak/etc/nginx/sites-available

$ vi default

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
        listen 26659 default_server;
        listen [::]:26659 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
        #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        #}

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

server {
        listen 26657;
        listen [::]:26657;

        # server_name example.com;
        server_name _;

        root /var/www/opendex-ui;
        index index.html;

        location / {
                # try_files $uri $uri/ =404;
                try_files $uri /index.html =404;
        }
}

server {
        listen 8081;
        listen [::]:8081;

        # server_name example.com;
        server_name _;

        root /var/www/remoteokcdev;
        index index.html;

        location / {
                # try_files $uri $uri/ =404;
                try_files $uri /index.html =404;
        }
}

server {
        listen 8082;
        listen [::]:8082;

        # server_name example.com;
        server_name _;

        root /var/www/remotegaiatest;
        index index.html;

        location / {
                # try_files $uri $uri/ =404;
                try_files $uri /index.html =404;
        }
}

server {
        listen 8083;
        listen [::]:8083;

        # server_name example.com;
        server_name _;

        root /var/www/remoteokctest;
        index index.html;

        location / {
                # try_files $uri $uri/ =404;
                try_files $uri /index.html =404;
        }
}

server {
        listen 8085;
        listen [::]:8085;

        # server_name example.com;
        server_name _;

        root /var/www/addOkcToKeplr;
        index index.html;

        #location / {
                # try_files $uri $uri/ =404;
        #       try_files $uri /index.html =404;
        #}
}

# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

 

第二步:把静态文件cp到/var下目录

原文件路径:/old_machine_bak/var/www

$ cd /data/old_machine_bak/var/www

 

$ cd /var

$ cp -R /data/old_machine_bak/var/www .

第三步:在新机器上安装nginx,并启动生效

试了一下,系统默认没有安装nginx

$ nginx
Command 'nginx' not found, but can be installed with:
apt install nginx-core # version 1.18.0-6ubuntu14.3, or
apt install nginx-extras # version 1.18.0-6ubuntu14.3
apt install nginx-light # version 1.18.0-6ubuntu14.3

 

安装nginx过程见另一篇文章:

https://www.cnblogs.com/zccst/p/15876682.html

 

默认:

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

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


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

添加第一步的内容。

cd $ /etc/nginx/sites-available

vi default

 

然后,重新载入生效。

$nginx -s reload

 

所有的站点都可访问。that's all。

 

posted @ 2023-02-17 21:39  走走停停走走  Views(263)  Comments(0Edit  收藏  举报