UOS下安装Nginx

一.安装

1.下载Nginx 目前采用nginx-1.18.0

http://nginx.org/en/download.html 

2.用管理员身份打开系统盘,进入usr/local 将nginx放置此处,并重命名

image.png

3.编译

./configure
image.png

4.安装

make && make install
image.png

5.启动nginx

cd /usr/local/nginx/sbin 

./nginx

PS 一开始启动报错,安装提示新建logs文件夹后重新启动,即可成功


image.png

6.验证

nginx默认监听80端口,浏览器输入localhost看到如下图即为成功。


image.png

二.部署

1.将打包好的文件放置

/usr/local/nginx/html
image.png

2.打开如下文件,将server中的内容修改为如图所示:

/usr/local/nginx/config/nginx.conf
image.png

3.重启服务

./nginx -s reload

注意此时重新访问出现403错误,重新进入nginx.conf 在首行加入

user  root;

之后重新启动服务,即可访问


image.png

最终结果如下:


image.png

结尾附属nginx.conf配置内容


user  root;
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       8028;
        server_name  localhost;
     root          html/dist;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            index  index.html index.htm;
            rewrite ^/([A-Za-z0-9]+)/([A-Za-z0-9]+)$ /$1 permanent;
            try_files $uri $uri/ /index.html;
        }

        location ^~/api {
            rewrite ^/api/(.*) /$1 break; #反向代理标识符 我们为/api
            proxy_pass xxxxxx;    #此处填写反向代理IP Port
            proxy_set_header X-Real-IP $remote_addr; #获取客户端真实IP
        }

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

}

你可能感兴趣的:(UOS下安装Nginx)