鼠扑 发表于 2024-11-30 12:46:38

linux(麒麟系统)安装nginx

linux(麒麟系统)安装nginx

1、apt-get安装nginx

安装命令:
sudo apt-get install nginx 2、检察是否安装乐成

nginx -v 3、启动nainx

service nginx start 4、重启

service nginx restart 5、停止

service nginx stop 6、启动后,在网页重输入ip地点,即可看到nginx的欢迎页面。至此nginx安装乐成

 http://localhost/

7、nginx文件安装完成之后的文件位置:

/usr/sbin/nginx:主程序
/etc/nginx:存放设置文件
/usr/share/nginx:存放静态文件
/var/log/nginx:存放日志 

8、修改设置文件:

进入 /etc/nginx  执行 sudo vim nginx.conf
修改设置文件后重新加载设置文件 nginx -s reload
 a、可以参考下面的设置:


worker_processes auto;
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;

#pid      logs/nginx.pid;


events {
    worker_connections1024;
}


http {
    include       mime.types;
    default_typeapplication/octet-stream;

    gzipon;
    gzip_min_length 5k;
    gzip_buffers 4 16k;
    gzip_comp_level 8;
    gzip_types text/css/woff application/javascript;
    sendfile      on;
    #tcp_nopush   on;

    keepalive_timeout600;

    #gzipon;

    client_max_body_size   20m;

    server {
      listen       8459;
      server_namelocalhost;



      location / {
            root   /data/www/qianduan;
            indexindex.html index.htm;
            try_files $uri $uri/ /index.html;
      }
         

location /api/ {
      proxy_pass http://localhost:8458/; #后台API地址
    }

      error_page   500 502 503 504/50x.html;
      location = /50x.html {
            root   html;
      }

      
    }
server {
listen 8458;
server_name api接口;

#允许跨域
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Credentials' 'true';
      add_header 'Access-Control-Allow-Methods' '*';
      add_header 'Access-Control-Allow-Headers' '*';

location / { proxy_pass http://127.0.0.1:9291;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; }
}

}
b、也可以将各server节点,单独创建一个.conf文件,放在/etc/nginx/conf.d目录,然后在nginx.conf通过以下句子引入
新建文件命令
sudo touch web.conf  编辑文件输入以下命令,按i,编辑完后按esc然后:wq退出
sudo vim web.conf 站点内容

server {
      listen       9898;
      server_namelocalhost;



      location / {
            root   /data/www/qianduan;
            indexindex.html index.htm;
            try_files $uri $uri/ /index.html;
      }
         

location /api/ {
      proxy_pass http://localhost:8458/; #后台API地址
    }

      error_page   500 502 503 504/50x.html;
      location = /50x.html {
            root   html;
      }

      
    }

https://i-blog.csdnimg.cn/blog_migrate/8f53dba9998e5fb99a7f8233f07395ae.jpeg


http {
    include       mime.types;
    default_typeapplication/octet-stream;

    gzipon;
    gzip_min_length 5k;
    gzip_buffers 4 16k;      
    gzip_comp_level 8;
    gzip_types text/css application/javascript;
    sendfile      on;
    #tcp_nopush   on;

    keepalive_timeout600;
   
    #gzipon;

    client_max_body_size   20m;
   
   
   include /etc/nginx/conf.d/*.conf;

}



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: linux(麒麟系统)安装nginx