IT虾米网

nginx配置

luoye 2022年05月14日 程序员 161 0

nginx配置

1.开发环境 vue+node
2.电脑系统 windows10专业版
3.在使用项目开发的过程中,我们经常会使用nginx进行转发,下面我我的总结,希望对你有所帮助!
4.nginx官网下载地址:

http://nginx.org/en/download.html 
//本次使用的版本是:1.18.0

5.下载之后,我们会得到这样的一个目录结构:

5-1.我们主要配置的是,如下图:

5-2.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       8010; 
        server_name  localhost; 
 
        #charset koi8-r; 
 
        #access_log  logs/host.access.log  main; 
 
        location / { 
            root   G:/chendistmo/dist; 
            index  index.html index.htm; 
            # proxy_pass http://192.168.137.63:3000; 
        } 
 
        location /api { 
            proxy_pass http://192.168.137.63: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; 
        #} 
    } 
 
 
    # 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; 
    #    } 
    #} 
 
} 

5-3.我们需要修改的地方,如下图:

5-4.使用终端进行到 nginx目录,如下图:

5-5.修改完成之后,我们用终端进行启动 nginx,命令如下:

1.start nginx.exe //启动nginx 
2.nginx -t //查看是否修改成功 
3.nginx -s reload //修改完成之后,重启启动 
4.nginx -s stop //关闭nginx

6.在浏览器输入localhost:8010,效果图如下:

6-1.数据请求也没有问题,效果图如下:

7.本期的分享到了这里就结束啦,是不是很nice,希望对你有所帮助,让我们一起努力走向巅峰!


评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

Ubuntu系统使用Nginx安装Laravel PHP Framework详细过程