nginx部署多个服务

nginx部署多个服务众所周知 Nginx enginex 是一个高性能的 HTTP 和反向代理服务 也是一个 IMAP POP3 SMTP 服务 Nginx 作为负载均衡服务 Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务 也可以支持作为 HTTP 代理服务对外进行服务 这样说你可能还不理解 但是如果我说 Apache 你肯定知道 nginx 就是类似与 Apache 这样的服务器 nginx 相对于

众所周知,Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务。

ngnix的详细介绍

下载nginx

官方网址:http://nginx.org/en/download.html

下载之后解压文件夹 

文件目录如下

  • conf是放配置文件的地方
  • html是存放页面的文件夹,也可以用新建的文件夹,需要到conf里面去配置

在这里插入图片描述
在文件最上方输入cmd,进入文件根目录
在这里插入图片描述
在命令行去启动nginx,下面是nginx的配置文件,比较简单,在conf里面找到nginx.conf文件,主要是修改这个配置文件,把你的项目放到nginx的根目录里面去,在下面的文件去修改







#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 {//服务,可以有多个server,对应多个服务
        listen       8099;//端口
        server_name  localhost;//服务名

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {//请求路径
            root   xiamenviews;//根目录下面的文件夹
            index  index.html index.htm;//文件夹下面的页面
        }

		location =/index.html {
            root xiamenviews;//首页文件夹
        }
        #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       8090;//端口
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

		location =/index.html {
            root views;
        }
        #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;
    #    }
    #}

}

然后我们可以在页面上访问那两个端口,localhsot:8099,localhost8090,分别访问两个页面,大致就是这样了,如果实际中有遇到什么问题欢迎留言,我们一起解决。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/204683.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月19日 下午7:46
下一篇 2026年3月19日 下午7:47


相关推荐

  • idea和pycharm什么关系_idea Python

    idea和pycharm什么关系_idea PythonvimEmulator:官网教程:https://www.jetbrains.com/help/pycharm/using-product-as-the-vim-editor.html指定部分快捷键时作为vim的快捷键还是作为pycharmide的快捷键在搜索栏里搜索vim…

    2026年4月15日
    10
  • rand()函数的用法[通俗易懂]

    rand()函数的用法[通俗易懂]C++中rand()函数的用法1、rand()不需要参数,它会返回一个从0到最大随机数的任意整数,最大随机数的大小通常是固定的一个大整数。2、如果你要产生0~99这100个整数中的一个随机整数,

    2022年8月2日
    8
  • C++快速入门教程

    C++快速入门教程author LeeG date 2020 12 10 1 C 语言和 C 的区别 面向过程语言 面向过程编程就是分析出解决问题的步骤 然后把这些步骤一步一步的实现 使用的时候一个一个的依次调用就可以了 C 面向对象语言 面向对象编程就是把问题分解成各个对象 建立对象的目的不是为了完成一个步骤 而是为了描述某个事物在整个解决问题的步骤中的行为 2 C 头文件及常用头文件介绍 include iostream usingnamespa iostream

    2026年3月26日
    1
  • python for循环语句怎么写

    python for循环语句怎么写想必大家都知道 python 循环语句吧 可以 python 循环语句有多种 比如 for 循环 while 循环 if else 等等 今天小编就给大家讲讲 for 循环语句 for 循环语句是 python 中的一个循环控制语句 任何有序的序列对象内的元素都可以遍历 比如字符串 列表 元组等可迭代对像 之前讲过的 if 语句虽然和 for 语句用法不同 但可以用在 for 语句下做条件语句使用 for 语句的基本格式 pyth

    2025年8月10日
    5
  • win7(64位)+IE8+QC9.0

    win7(64位)+IE8+QC9.0

    2021年9月6日
    97
  • 零基础玩转混元翻译:HY-MT1.5-1.8B保姆级部署教程

    零基础玩转混元翻译:HY-MT1.5-1.8B保姆级部署教程

    2026年3月12日
    1

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号