• ubuntu环境下通过apt-get安装软件 nginx 怎么配置文件


    nginx安装

    首先是安装nginx,环境依然是ubuntu12.04(64位),通过下面命令:

    sudo apt-get install nginx
    
    • 1

    nginx启动

    安装好之后就是启动,目前我知道的在ubuntu下有两种启动方式:

    sudo /etc/init.d/nginx start #通过init.d下的启动文件启动。
    
    • 1
    sudo service nginx start #通过ubuntu的服务管理器启动
    
    • 1

    nginx打开

    在浏览器中输入http://localhost,看看是不是出现“Welcome to nginx!”的页面。如果没有的话,先继续往下看配置。

    nginx配置

    在我的系统中nginx的配置文件在/etc/nginx下。
    打开nginx.conf文件,配置如下:

    # For more information on configuration, see:
    #   * Official English Documentation: http://nginx.org/en/docs/
    #   * Official Russian Documentation: http://nginx.org/ru/docs/
    
    user root;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    
    # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
    include /usr/share/nginx/modules/*.conf;
    
    events {
        worker_connections 1024;
    }
    
    http {
        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  /var/log/nginx/access.log  main;
    
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
    
        keepalive_timeout     3600;
        client_header_timeout 3600;
        client_body_timeout   3600;
        proxy_connect_timeout 3600;
        proxy_send_timeout    3600;
        proxy_read_timeout    3600;
    
        types_hash_max_size 2048;
    
        client_max_body_size  36G;
    
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
    
        # Load modular configuration files from the /etc/nginx/conf.d directory.
        # See http://nginx.org/en/docs/ngx_core_module.html#include
        # for more information.
        include /etc/nginx/conf.d/*.conf;
    
        # Mccts-start
        server {
            listen          2333;
            server_name     localhost;
            root            /home/mccts/start;
            index           index.html index.htm;
    
            location / {
                # 截取404的uri,传给 @router
                try_files $uri $uri/    @router;
            }
      
            location @router {
                 # 接到截取的uri 并按一定规则重写uri和vue路由跳转
                rewrite ^.*$    /index.html last;
            }
        }
    
        # McctsControl
        server {
            listen        9527;
            server_name   localhost;
            autoindex     on;
            root          /home/mccts/mccts-control/web;
            index         index.html index.htm;
    
            location / {
                # 截取404的uri,传给 @route
                try_files $uri $uri/   @router;
            }
    
            location /control/ {
                proxy_pass          http://127.0.0.1:8080/;
                #proxy_pass          http://192.168.1.28:8080/;
                proxy_redirect      default;
                proxy_set_header    Host                     $host;
                proxy_set_header    X-Real-IP                $remote_addr;
                proxy_set_header    X-Forwarded-For          $proxy_add_x_forwarded_for;
              }
    
              location /analysis/ {
                proxy_pass          http://127.0.0.1:8081/;
                proxy_redirect      default;
                proxy_set_header    Host                     $host;
                proxy_set_header    X-Real-IP                $remote_addr;
                proxy_set_header    X-Forwarded-For          $proxy_add_x_forwarded_for;
              }
    
    	  location /Rocket/ {
    	    proxy_pass          http://127.0.0.1:3101/Rocket/;
    	  }
    
              location @router {
                # 接到截取的uri 并按一定规则重写uri和vue路由跳转
                rewrite ^.*$ /index.html last;
              }
        }
    
        # McctsAnalysis
        server {
            listen          9528;
            server_name     localhost;
            root            /home/mccts/mccts-analysis/web;
            index           index.html index.htm;
    
            location / {
                # 截取404的uri,传给 @route
                try_files $uri $uri/   @router;
            }
    
            location /analysis {
                proxy_pass          http://127.0.0.1:8081/;
                proxy_redirect      default;
                proxy_set_header    Host                     $host;
                proxy_set_header    X-Real-IP                $remote_addr;
                proxy_set_header    X-Forwarded-For          $proxy_add_x_forwarded_for;
            }
        }
    
        # McctsObject
        server {
            listen          9529;
            server_name     localhost;
            root            /home/mccts/mccts-object/web;
            index           index.html index.htm;
    
            location / {
                # 截取404的uri,传给 @route
                try_files $uri $uri/   @router;
            }
    
            location /object {
                proxy_pass          http://127.0.0.1:8083/;
                proxy_redirect      default;
                proxy_set_header    Host                     $host;
                proxy_set_header    X-Real-IP                $remote_addr;
                proxy_set_header    X-Forwarded-For          $proxy_add_x_forwarded_for;
            }
    
            location @router {
                # 接到截取的uri 并按一定规则重写uri和vue路由跳转
                rewrite ^.*$    /index.html last;
            }
        }
    
    
        # McctsBallistic
        server {
            listen          3101;
            server_name     localhost;
    	
    	add_header 'Access-Control-Allow-Origin' '*';
    	add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
    	add_header 'Access-Control-Allow-Headers' 'Content-Type';
    
    	if ($request_method = 'OPTIONS') {
    	    return 200;
    	}
    
    	location /Rocket/ {
    	    proxy_pass          http://127.0.0.1/Rocket/;
    	    proxy_redirect      default;
    	    proxy_set_header    Host                     $host;
    	    proxy_set_header    X-Real-IP                $remote_addr;
    	    proxy_set_header    X-Forwarded-For          $proxy_add_x_forwarded_for;  
    	}
        }
    # Settings for a TLS enabled server.
    #
    #    server {
    #        listen       443 ssl http2 default_server;
    #        listen       [::]:443 ssl http2 default_server;
    #        server_name  _;
    #        root         /usr/share/nginx/html;
    #
    #        ssl_certificate "/etc/pki/nginx/server.crt";
    #        ssl_certificate_key "/etc/pki/nginx/private/server.key";
    #        ssl_session_cache shared:SSL:1m;
    #        ssl_session_timeout  10m;
    #        ssl_ciphers PROFILE=SYSTEM;
    #        ssl_prefer_server_ciphers on;
    #
    #        # Load configuration files for the default server block.
    #        include /etc/nginx/default.d/*.conf;
    #
    #        location / {
    #        }
    #
    #        error_page 404 /404.html;
    #            location = /40x.html {
    #        }
    #
    #        error_page 500 502 503 504 /50x.html;
    #            location = /50x.html {
    #        }
    #    }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    
    #user  nobody;
    worker_processes  1;
    
    #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       80;
        #     server_name  localhost;
        #     add_header Access-Control-Allow-Origin '*' always;
    
        #     #charset koi8-r;
    
        #     #access_log  logs/host.access.log  main;
    
        #     location / {
        #         root   html/emulate2/publish;
        #         # index  index.html index.htm;
        #     }
        # }
    
        server {
            listen       8080;
            server_name  localhost;
            add_header 'Access-Control-Allow-Origin' '*';
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   html/Cesium/;
                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;
            #}
        }
    
        server {
            listen       4444;
            server_name  localhost;
            add_header Access-Control-Allow-Origin '*' always;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                # root   C:/MapDownload/mapabc/satellite;
                root   html/satellite;
                autoindex on;
                # index  index.html index.htm;
            }
        }
    
        server {
            listen       3200;
            server_name  _;
            # add_header Access-Control-Allow-Origin '*' always;
            # add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
            # add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,Accept';
    
            # if ($request_method = 'OPTIONS') {
            #   return 204;
            # }
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                # proxy_pass          http://127.0.0.1:8765/; 
                # proxy_redirect      default;
                # proxy_set_header    Host                $host;
                # proxy_set_header    X-Real-IP           $remote_addr;
                # proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for; 
                root   html/Emulate;
                autoindex on;
                # index  index.html index.htm;
            }
        }
    
    
        # server {
        #     listen       8765;
        #     server_name  localhost;
        #     add_header Access-Control-Allow-Origin '*' always;
        #     add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
        #     add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,Accept';
    
        #     #charset koi8-r;
    
        #     #access_log  logs/host.access.log  main;
    
        #     location / {
        #          proxy_pass  http://127.0.0.1:8001/; 
    
        #     }
        # }
    
    
        # 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;
        #    }
        #}
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195

    这样就ok了,重启你的nginx:sudo service nginx restart.
    接着你直接访问 http://127.0.0.1就可以访问

  • 相关阅读:
    机器学习笔记 - 自相关和偏自相关简介
    关联查询系统
    组合数的求解(打表,逆元,Lucas 定理,大整数求解)
    『Halcon与C#混合编程』005_设置控件焦点、Creation、HalconAPI.CancelDraw();
    查看svn当前版本信息
    wireshark分析tcp协议(一)三次握手【理论 + 实操】
    [附源码]java毕业设计医院疫情疾控管理系统
    AttributeError: module ‘gradio‘ has no attribute ‘ClearButton‘解决方案
    【Python零基础入门篇 · 1】:print()函数的使用和转义字符、原字符总结
    机器学习第8天:SVM分类
  • 原文地址:https://blog.csdn.net/qq_53810245/article/details/126585243