当前位置: 首页 > ds >正文

nginx安装

一,下载解压步骤这里省略
二、安装
root用户进到nginx目录输入以下指令

./configure
make && sudo make install

三、设置开机自动启动

 vi /etc/systemd/system/nginx.service
[Unit]
Description=nginx-server
After=network.target[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true[Install]
WantedBy=multi-user.target

重载系统服务

systemctl daemon-reload

开启开机启动

systemctl enable nginx

四、以下是nginx配置文件根据项目需求写

#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;client_max_body_size 20m;#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;upstream myserver {server 127.0.0.1:8080;}server {listen       80;server_name    192.168.0.106; //这里是服务器ip#charset koi8-r;#access_log  logs/host.access.log  main;location / {alias   /srv/www/;# 用于配合 browserHistory使用try_files $uri $uri/ /index.html;#禁止缓存不然更新文件,不出效果#     add_header Cache-Control no-cache;#       add_header Cache-Control private; }
location  /abc/ {  #后台接口地址(我们部署去掉了/abc项目名,如果你有请加上)注意 这个abc是路由路径proxy_pass        http://myserver/abc/;proxy_redirect off;#真实IP获取proxy_set_header  Host             $host;proxy_set_header  X-Real-IP        $remote_addr;set $my_proxy_add_x_forwarded_for $proxy_add_x_forwarded_for;if ($proxy_add_x_forwarded_for ~* "127.0.0.1"){set $my_proxy_add_x_forwarded_for $remote_addr;}proxy_set_header   X-Forwarded-For $my_proxy_add_x_forwarded_for;}#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;#    }#}}

注意:用systemctl启动服务nginx,网站报403错,直接命令运行nginx启动没错。两个原因,1,启动用户和用户名不一样,conf加user=root(与这个无关)。2,主要原因还是selinux的问题
403报错,权限问题,
巨坑:SELinux设置为开启状态(enabled)的原因。

http://www.xdnf.cn/news/15438.html

相关文章:

  • [Subtitle Edit] 语言文件管理.xml | 测试框架(VSTest) | 构建流程(MSBuild) | AppVeyor(CI/CD)
  • COZE token刷新
  • 代码随想录|图论|15并查集理论基础
  • ARC 03 从Github Action job 到 runner pod
  • Java4种设计模式详解(单例模式、工厂模式、适配器模式、代理模式)
  • 【DeepSeek实战】29、金融数据抓取全攻略:从AKShare到API实战,Python量化分析必备指南
  • JavaScript 中一些常见算法的实现及详细解析
  • 详解Linux下多进程与多线程通信(二)
  • Web应用性能优化之数据库查询实战指南
  • 时间的弧线,逻辑的航道——标准单元延迟(cell delay)的根与源
  • 单页面和多页面的区别和优缺点
  • 通用定时器GPT
  • 【Linux学习笔记】认识信号和信号的产生
  • 区块链平台之以太坊深入解读:技术、经济与生态的全面解析
  • 剑指offer57_和为S的两个数字
  • 串口连接工控机
  • 【离线数仓项目】——电商域DIM层开发实战
  • 服务端高效处理拖拽排序
  • 锁相环初探
  • 【6.1.2 漫画分布式事务技术选型】
  • BaseDao 通用更新方法设计与实现
  • 【PMP备考】敏捷思维:驾驭不确定性的项目管理之道
  • Java ThreadLocal详解:从原理到实践
  • 快速过一遍Python基础语法
  • 第34次CCF-CSP认证第4题,货物调度
  • 零基础搭建监控系统:Grafana+InfluxDB 保姆级教程,5分钟可视化服务器性能!​
  • Python 中的 encode() 和 decode() 方法详解
  • JavaSE常用类
  • 开阳630HV100芯片的外设配置
  • 【C++】封装红黑树模拟实现set和map