欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

阿里云配置nginx服务器上线vue项目

程序员文章站 2022-06-15 12:37:39
...

一、购买服务器

购买地址:https://www.aliyun.com/product/swas?spm=5176.12825654.eofdhaal5.3.2a162c4a69sEWl&aly_as=YpnwUhRpf

二、配置服务器环境-nginx

1.查看服务器ip地址
2.设置远程连接密码
阿里云配置nginx服务器上线vue项目
打开git bash

ssh aaa@qq.com + ip/域名地址

阿里云配置nginx服务器上线vue项目
在服务器中安装环境依赖

yum install gcc-c++  
yum install pcre pcre-devel  
yum install zlib zlib-devel  
yum install openssl openssl--devel

安装nginx
按步骤输入敲回车

cd /usr/local //首先进入/usr/local目录
wget -c https://nginx.org/download/nginx-1.12.1.tar.gz //从官网下载最新版的nginx
tar -zxvf nginx-1.12.1.tar.gz //解压nginx压缩包
cd  nginx-1.12.1  //进入nginx-1.12.1 目录
./configure
make
make install

启动nginx服务

whereis nginx  //查找nginx的位置
cd /usr/local/nginx/sbin/  //打开nginx的目录
./nginx   //启动
./nginx -s stop
./nginx -s quit
./nginx -s reload  //重新启动
./nginx -s quit: 此方式停止步骤是待nginx进程处理任务完毕进行停止。
./nginx -s stop: 此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程

三、配置网站目录和域名解析

配置 /usr/local/nginx/conf下的nginx.conf文件


#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       1111;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

		# location /maizuo/ {
		# 	proxy_pass https://m.maizuo.com/;
		# }

		# location /api/ {
		# 	proxy_pass http://localhost:3000/;
		# }

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

配置config完成后需要 ./nginx -s reload 重新启动
vue项目打包后使用ftp上传至 /usr/local/nginx/html
访问ip或域名即可成功访问

相关标签: 从零开始