Nginx部署多站点(多端口号)

1、 新建前端文件夹;

 

 2、 将前端打包好的文件分别放在项目文件夹中;

 

3、 使用notepad++打开nginx配置文件;

 

4、 添加server部分;

 

#项目1
    server {
	
        listen       8886;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

		location / {
            root   html/nxjcyj-html/;
            index  index.html index.htm;
			try_files $uri $uri/ @router; #截取404的uri,传给@router
        }
		
		location @router {
			rewrite ^.*$ /index.html last; #接到截取的uri,并按一定规则重写uri和vue路由跳转
		}
			
		location /api {
			proxy_pass http://localhost:8000;
		}

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

	#项目2
	server {
	
        listen       8885;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

		location / {
            root   html/szjcyj-html/;
            index  index.html index.htm;
			try_files $uri $uri/ @router; #截取404的uri,传给@router
        }
		
		location @router {
			rewrite ^.*$ /index.html last; #接到截取的uri,并按一定规则重写uri和vue路由跳转
		}
			
		location /api {
			proxy_pass http://localhost:8000;
		}

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

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 我可以给你提供一些有用的参考资料,来帮助你部署Nginx: 1. Nginx官方文档,可以提供有关安装和配置的步骤; 2. 在Github上有一些Nginx脚本,可以帮助你自动化部署; 3. 在StackOverflow上也有很多有关Nginx部署的问答,可以帮助你解决各种问题。 ### 回答2: Nginx一键部署脚本是一个自动化工具,用于简化Nginx服务器的安装和配置过程。这个脚本可以帮助用户快速搭建一个功能强大的web服务器,提供高性能和可靠性。 使用Nginx一键部署脚本的好处有以下几点: 1. 简化安装过程:传统上,安装Nginx需要手动下载、解压、编译和配置。而使用一键部署脚本可以自动完成这些步骤,大大简化了安装过程,减少了出错的可能性。 2. 快速配置:一键部署脚本会提供一些默认的配置选项,用户只需选择一些基本配置,比如端口号、网站根目录等,就可以快速配置Nginx服务器。 3. 自动更新与管理:一键部署脚本还可以自动检测Nginx的更新,如果有新版本可用,脚本会自动下载和安装更新。此外,它还提供了管理命令,如启动、停止和重启Nginx服务器。 4. 安全性和稳定性:脚本会按照最佳实践配置Nginx,包括限制访问权限、启用SSL/TLS加密等功能,提高服务器的安全性。同时,Nginx本身就以其高性能和稳定性而闻名,使用这个脚本可以确保服务器的运行质量。 总而言之,Nginx一键部署脚本是一个方便、快捷、安全且可靠的工具,帮助用户快速搭建和管理Nginx服务器。无论是个人开发者还是企业级应用,都可以受益于这个脚本提供的便利和功能。 ### 回答3: nginx一键部署脚本是一个方便快捷地安装和配置nginx的工具。它可以帮助我们简化nginx服务器安装的流程,降低了操作难度和时间成本。 一键部署脚本通常包含了以下几个步骤: 1. 检查系统环境:脚本会自动检测操作系统的版本和架构,确保安装的nginx适配当前系统环境。 2. 下载nginx安装包:脚本会自动从官方网站或指定镜像站点下载最新的nginx安装包。 3. 安装nginx:脚本会解压nginx安装包并进行相应的依赖库检查和安装,保证nginx正常运行所需的环境和软件。 4. 配置nginx:脚本会根据用户的需求自动创建默认配置文件,并可以根据具体情况进行修改和定制化设置。 5. 启动nginx:安装完成后,脚本会自动启动nginx服务,并开启自启动功能,确保nginx在系统重启后可以自动运行。 6. 检查nginx状态:脚本会检查nginx的运行状态,并输出相关信息,以便用户确认nginx是否成功安装和启动。 通过使用nginx一键部署脚本,我们可以快速搭建一个稳定、安全的nginx服务器,为网站和应用程序提供高性能的HTTP和反向代理服务。无论是个人开发者还是企业组织,都可以受益于这样的脚本,提高系统部署的效率和质量。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值