• 腾讯云服务器、nginx部署loopback


    最近在研究学习nginx,买了腾讯云服务器、在阿里上申请了域名,部署项目遇到很多问题记录一下,以备后用:

    1.在腾讯服务器买好(如果登录密码不知道可以重置),阿里域名申请好后(也可以在腾讯上申请域名),需要添加安全组,创建不同的规则,在入站规则中添加各个需要的TCP端口,具体创建方式自行百度。

    2.登录到阿里域名后申请域名解析,添加网址解析记录,设置@、www等,添加对应项目的端口。

    3.在服务器上部署好项目,安装nginx,将loopback项目部署。安装命令:

    sudo apt-get install nginx 

    4.nginx基本操作命令

    5.如果登录默认用户时,创建文件的权限不够,可以执行命令将文件变成当前用户私有文件:

    sudo chown -R 组名(随便写):用户名 文件夹/

    重启:sudo service nginx restart

    修改配置文件:vi /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/*;

            server{
                    listen 80;
                    server_name www.xxxxx.com xxxxx.com;
                    location /restful {
                            # proxy_pass http://nxweiqi;
                            # root /;
                            proxy_redirect off;
                            proxy_set_header  Host $host; #请求主机头字段,否则为服务器名称。
                            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for ;
                            proxy_set_header Accept-Encoding "";
                            proxy_set_header X-Real-IP $remote_addr;
                            add_header 'Access-Control-Allow-Origin' '*';
                            proxy_pass http://xxxxx.com:8000/restful/;
                    }
                    location /wqgl/ {
                            proxy_redirect off;
                            proxy_pass http://xxxxx.com:3001/;
                    }
                    # location / {
                           # try_files $uri $uri/ =404;
                    # }
    
    
            }
    }
    #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;
    #       }
    #}

    切记 proxy_pass http://xxxxx.com:3001/,最后的"/"必须加上。

  • 相关阅读:
    HYSBZ 2818 gcd
    hdu1695 GCD
    HYSBZ 2301
    poj 2096
    正则表达式匹配HTML标签或标记
    [转载]Sed 命令详解 正则表达式元字符
    [转载]Shell删除各种注释的脚本
    [转载]sed实现直接修改文件内容
    [转载]强大的grep用法详解:grep与正则表达式
    [转载]【Shell脚本】逐行处理文本文件
  • 原文地址:https://www.cnblogs.com/jlj9520/p/10510929.html
Copyright © 2020-2023  润新知