ubuntu环境下 nginx 怎么配置文件

2023-10-30

nginx安装

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

sudo apt-get install nginx

nginx启动

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

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

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

}


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

}

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ubuntu环境下 nginx 怎么配置文件 的相关文章

随机推荐

  • 2021年最新IT职业技能全套图谱

    2021年最新IT职业技能图谱出炉 如图 包含各个方向 各个专业 按照以上技能图谱学习 保证你拿高薪
  • 解决ROS系统 rosdep update超时问题的新方法

    由于近期国内Github Raw的可用IP越来越少 通过修改hosts文件解决rosdep update超时问题的方法已经不太好用 本文通过修改rosdep源码中下载资源的函数来解决这一问题 网站https ghproxy com 支持gi
  • c++时间戳获取和转换

    1 使用api 可以使用windows下和linux下api函数来获取 比较简单 如下所示 int64 t getTimeStamp 毫秒数 int mSecond 0 if defined WIN32 SYSTEMTIME sys Get
  • video-player实现hls播放全过程

    安装依赖 npm install vue video player save 引入样式 第一个是videoJs的样式 后一个是vue video player的样式 因为考虑到我其他业务组件可能也会用到视频播放 所以就放在了main js内
  • typeScript--[数据定义]

    一 安装ts 1 命令行运行如下命令 全局安装 TypeScript npm install g typescript 2 安装完成后 在控制台运行如下命令 检查安装是否成功 tsc V 二 创建ts文件 1 创建一个day01 ts文件
  • Linux·C/C++主线程对子线程的影响

    这篇文章主要介绍了简单了解C语言中主线程退出对子线程的影响 文中通过示例代码介绍的非常详细 对大家的学习或者工作具有一定的参考学习价值 需要的朋友可以参考下 对于程序来说 如果主进程在子进程还未结束时就已经退出 那么Linux内核会将子进程
  • Android几种定时任务实现方式汇总

    目录 前言 方式一 AlarmManager API19之前AlarmManager常用的一些方法 参数说明 使用举例 AlarmManager实例Demo讲解 包含版本适配以及高版本设置重复闹钟 AlarmManager总结 方式二 Ha
  • 设计模式——责任链

    本文说明 在学习 Java EE互联网轻量级框架整合开发 此书时 里面提到了几种设计模式 我在学习这几种设计模式时写了笔记 放上来让大家共同学习 如果有错误 望指出 本章由两部分组成 1 基本概念 关键代码讲解 2 完整例子 基本概念 关键
  • WEB服务器如何确定哪个Servlet处理请求

    文章目录 一 WEB服务器 二 Servlet容器 三 Servlet生命周期 创建对象 初始化 处理请求 销毁 四 WEB服务器确定Servlet处理请求过程 一 WEB服务器 是指计算机和运行在它上面的服务器软件的总和 能提供网上信息浏
  • vue中实现ueditor上传图片遇到的几个问题及解决方案

    vue中实现ueditor上传图片功能 遇到的问题 初始化ue组件无法正常显示 无法加载 单图上传的图标变灰无法点击 or 多图上传显示后端配置项没有正常加载 上传插件不能正常使用 配置上传接口错误 请求报404 无法找到 上传后 服务端显
  • QT 信号和槽需要注意的几点

    connect 发出信号的对象指针 SIGNAL 信号函数原型 响应信号的对象 SLOT 槽函数原型 这里先说说信号及槽与普通成员函数有什么区别 只是定义的区域不同而已 信号函数需要声明在头文件的signals 关键字后面 无需实现 而槽则
  • c语言的标识符必须以字母或下划线开头,大一C语言选择题及答案

    第1章 C语言程序设计概述 一 选择题 1 以下叙述中正确的是 A A C语言程序中注释部分可以出现在程序中任意合适的地方 B 花括号 和 只能作为函数体的定界符 C 构成C语言程序的基本单位是函数 所有函数名都可以由用户命名 D 分号是C
  • pandas 用read_csv读取txt文件时,部分行丢失

    用pandas 的 read csv 来读取txt文件时 出现了部分行丢失的情况 原因是某行中有单个英文引号 导致 n换行符失效 多行连成了一行 直到遇到下一个单个引号 例如 txt文件如下 这里有一个未闭合的引号 就是它 这是正常的第二行
  • 丑数 打表+二分查找

    1010 只包含因子2 3 5 的数 题目链接 http www 51nod com Challenge Problem html problemId 1010 引用知识 https baike baidu com item E4 B8 9
  • DevOps系列之 —— 持续开发与集成(六)静态代码检查

    DevOps系列之 DevOps概览 一 软件产业和交付模式发展趋势 DevOps系列之 DevOps概览 二 新型软件技术及交付模式 DevOps系列之 DevOps概览 三 DevCloud HE2E DevOps 框架及其主要服务 D
  • Python头歌合集(题集附解)

    目录 一 Python初识 基本语法 第1关 Hello Python 第2关 我想看世界 第3关 学好Python 第4关 根据圆的半径计算周长和面积 第5关 货币转换 二 turtle简单绘图 第1关 英寸与厘米转换 第2关 绘制等边三
  • java使用easyExcel实现Excel导入和导出

    1 引入依赖
  • CSV文件 分类

    org deeplearning4j examples dataexamples BasicCSVClassifier 数据格式 一定要搞清楚数据格式 输入输出 才能构建网络 对应的是你手头有什么 想要做什么 预测什么 训练日志 这个例子只
  • 第六章:string类

    系列文章目录 文章目录 系列文章目录 前言 为什么学习string类 C语言中的字符串 ASCII Unicode UTF 8 UTF 16 UTF 32 GBK 标准库中的string类 string类 总结 string类的常用接口说明
  • ubuntu环境下 nginx 怎么配置文件

    文章目录 nginx安装 nginx启动 nginx打开 nginx配置 nginx安装 首先是安装nginx 环境依然是ubuntu12 04 64位 通过下面命令 sudo apt get install nginx nginx启动 安