美文网首页
Nginx 不同版本的配置

Nginx 不同版本的配置

作者: Mark同学 | 来源:发表于2019-12-26 17:03 被阅读0次

nginx/1.10.3 (Ubuntu)

  • 长连接登录
 ssh -o ServerAliveInterval=60 root@XXX.com
  • 查看 linux 版本 lsb_release -a
LSB Version:    core-9.20160110ubuntu0.2-amd64:core-9.20160110ubuntu0.2-noarch:security-9.20160110ubuntu0.2-amd64:security-9.20160110ubuntu0.2-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.6 LTS
Release:    16.04
Codename:   xenial
  • 安装上 nginx 之后,访问其默认端口是可以看到欢迎信息的
  • 查看 nginx 版本 nginx -v
nginx version: nginx/1.10.3 (Ubuntu)
  • 查看 nginx 配置文件的位置 nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
  • 查看配置文件的插槽 nano /etc/nginx/nginx.conf
  GNU nano 2.5.3                                            File: /etc/nginx/nginx.conf                                                                                                

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        # 进入下面的文件配置代理
        include /etc/nginx/sites-enabled/*;

}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}
  • 修改配置文件 nano /etc/nginx/sites-enabled/default
  GNU nano 2.5.3                                         File: /etc/nginx/sites-enabled/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 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 localhost;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                # try_files $uri $uri/ =404;
                proxy_pass  http://localhost:3000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "Upgrade";
        }
        location /api/ {
                proxy_pass http://localhost:6060;
                proxy_set_header Host $host;
        }
        ################### 修改结束 ######################

        # 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;
        #}
}


# 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;
#       }
#}
  • 注意:如果是 nginx 代理静态资源,一定不要配置在 root 目录下,有权限问题
  • 注意:location /api 的映射在这个项目里可以去掉了
    nano /etc/nginx/sites-enabled/default
server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html/build;
        index index.html index.htm index.nginx-debian.html;
        server_name bactravel.com;

        location / {
                 try_files $uri $uri/ /index.html;
        }
}
  • 用 pm2 启动 nodejs 后端进程 pm2 start www.js
  • 查看 pm2 接管的进程 pm2 list
  • 查看 pm2 日志 pm2 logs
  • 查看 pm2 显示器 pm2 monit
  • 查看端口号 netstat -tpln
// 从上倒下依次:
// mongodb 数据库
// redis 缓存数据库
// nginx 代理服务器
// ssh 连接端口
// react 前端端口(手动启动)
// mysql 数据库
// nodejs 后端进程 (由 pm2 启动)
// 代理接口 (由nginx 提供)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      452/mongod      
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      789/redis-server 12
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      804/nginx -g daemon
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      875/sshd        
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      2334/node       
tcp6       0      0 :::3306                 :::*                    LISTEN      794/mysqld      
tcp6       0      0 :::6060                 :::*                    LISTEN      1827/www.js     
tcp6       0      0 :::80                   :::*                    LISTEN      804/nginx -g daemon

nginx/1.17.3 (MacOS)

  • 修改配置文件 nano /usr/local/etc/nginx/nginx.conf
#user  nobody;
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    ######################## 修改开始 #####################
    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

    location /api/ {
        proxy_pass http://localhost:8000;
        proxy_set_header Host $host;
    }

    ###################### 修改结束 #######################
        #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/*;
}

相关文章

  • Nginx配置不同端口虚拟主机

    Nginx简易配置不同端口的虚拟主机 系统环境及nginx版本: 修改配置文件,添加如下内容: 创建各自nginx...

  • Nginx 不同版本的配置

    nginx/1.10.3 (Ubuntu) 长连接登录 查看 linux 版本 lsb_release -a 安装...

  • Nginx和Apache下https配置

    Nginx下https配置 注:Nginx版本1.12,Apache版本2.4,以下配置如需复制请去除注释,配置仅...

  • mac 配置Nginx服务

    安装nginx brew install nginx安装后使用nginx -v查看nginx版本 配置nginx ...

  • nginx中的server_name

    nginx版本 nginx version: nginx/1.18.0 发现问题 今天在nginx中配置serve...

  • nginx使用简记

    当前版本 nginx-1.16.0 常用命令: 验证配置是否正确: nginx -t查看Nginx的版本号:ngi...

  • nginx http、 https、 http2配置

    nginx http、 https、 http2配置 nginx版本:1.12.2 *注:以下配置重启才能生效 h...

  • nginx平滑升级与回滚

    1.安装配置1.6版本的 nginx 2.查看版本和模块 3.访问验证 4.升级nginx 将 nginx 版本进...

  • ngingx 开机启动

    ngingx 开机启动 nginx版本:1.12.2 nginx http、https&http2 配置

  • nginx平滑升级方案

    下载版本 下载新版本的nginx源码包 备份配置 备份旧nginx二进制文件和配置文件 配置安装 解压下载的源码包...

网友评论

      本文标题:Nginx 不同版本的配置

      本文链接:https://www.haomeiwen.com/subject/pnlloctx.html