亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

搜索
博主信息
博文 291
粉絲 0
評論 0
訪問量 450141
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
Linux安裝Nginx并配置啟動命令
原創(chuàng)
1710人瀏覽過

鏡像下載、域名解析、時間同步請點擊 阿里云開源鏡像站

安裝前準備工作

因為Nginx依賴于gcc的編譯環(huán)境,所以,需要安裝編譯環(huán)境來使Nginx能夠編譯起來

  1. yum install gcc-c++

Nginx的http模塊需要使用pcre來解析正則表達式,需要安裝pcre

  1. yum install -y pcre pcre-devel

安裝依賴的解壓包

  1. yum install -y zlib zlib-devel

ssl 功能需要 openssl 庫,安裝 openssl

  1. yum install -y openssl openssl-devel

下載Nginx

可以自己建立一個包,將nginx下載到這個路徑,我設置的路徑/opt/crm/nginx

如果需要其他nginx版本的可以參考 nginx倉庫

  1. wget http://nginx.org/download/nginx-1.10.2.tar.gz

下載完之后解壓

  1. tar zxvf nginx-1.10.2.tar.gz

進入到解壓之后的nginx目錄

  1. [root@localhost src]# cd nginx-1.10.2
  2. [root@localhost nginx-1.10.2]# ./configure && make && make install

如果要使用ssl

  1. ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

注意:如果配置了ssl,檢查配置文件時報錯

  1. nginx -t
  2. nginx:[emerg]unknown directive ssl錯誤
  3. 去到nginx安裝的目錄
  4. ./configure --with-http_ssl_module
  5. 注意要把新生成的文件復制到對應目錄
  6. cp objs/nginx /usr/local/nginx/sbin/nginx
  7. 顯示成功就搞定
  8. [root@iZ2ze02hshpth1x0vxo8r6Z sbin]# ./nginx -t
  9. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  10. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
  11. [root@iZ2ze02hshpth1x0vxo8r6Z sbin]#

安裝完之后查看安裝目錄

  1. [root@izbp10k7vskcf4soxxbp5gz /]# whereis nginx
  2. nginx: /usr/local/nginx
  3. [root@izbp10k7vskcf4soxxbp5gz /]#

通過查找文件名方式

  1. [root@izbp10k7vskcf4soxxbp5gz /]# find / -name nginx
  2. /opt/crm/nginx
  3. /opt/crm/nginx/nginx-1.10.2/objs/nginx
  4. /usr/local/nginx
  5. /usr/local/nginx/sbin/nginx
  6. [root@izbp10k7vskcf4soxxbp5gz /]#

直接執(zhí)行

  1. [root@izbp10k7vskcf4soxxbp5gz /]# /usr/local/nginx/sbin/nginx
  2. [root@izbp10k7vskcf4soxxbp5gz /]# ps -ef | grep nginx
  3. root 4666 1 0 09:32 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  4. nobody 4667 4666 0 09:32 ? 00:00:00 nginx: worker process
  5. root 5028 29443 0 09:40 pts/0 00:00:00 grep --color=auto nginx
  6. [root@izbp10k7vskcf4soxxbp5gz /]#

在瀏覽器輸入服務器IP地址

file

增加systemctl命令方式啟動

直接啟動和關閉nginx的方式

  1. 啟動nginx的命令為 /usr/local/nginx/sbin/nginx
  2. 停止nginx的命令為 /usr/local/nginx/sbin/nginx -s stop
  3. 重啟nginx的命令為 /usr/local/nginx/sbin/nginx -s reload

配置方式 去到/usr/lib/systemd/system/目錄新建一個nginx服務,給予執(zhí)行權限

  1. vim /usr/lib/systemd/system/nginx.service
  2. chmod +x /usr/lib/systemd/system/nginx.service

打開文件nginx.service新建內(nèi)容

  1. [Unit]
  2. Description=nginx - high performance web server
  3. After=network.target remote-fs.target nss-lookup.target
  4. [Service]
  5. Type=forking
  6. PIDFile=/usr/local/nginx/logs/nginx.pid
  7. ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
  8. ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  9. ExecReload=/usr/local/nginx/sbin/nginx -s reload
  10. ExecStop=/usr/local/nginx/sbin/nginx -s stop
  11. ExecQuit=/usr/local/nginx/sbin/nginx -s quit
  12. PrivateTmp=true
  13. [Install]
  14. WantedBy=multi-user.target

保存之后重載Ststemctl命令

  1. 在啟動服務之前,需要先重載systemctl命令
  2. systemctl daemon-reload

配置完之后

  1. systemctl status nginx
  2. systemctl start nginx
  3. systemctl stop nginx
  4. systemctl restart nginx

附上配置

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 65535;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. gzip on;
  22. #允許壓縮的最小字節(jié)數(shù)
  23. gzip_min_length 1k;
  24. #4個單位為16k的內(nèi)存作為壓縮結果流緩存
  25. gzip_buffers 4 16k;
  26. #設置識別HTTP協(xié)議版本,默認是1.1
  27. gzip_http_version 1.1;
  28. #gzip壓縮比,可在1~9中設置,1壓縮比最小,速度最快,9壓縮比最大,速度最慢,消耗CPU
  29. gzip_comp_level 2;
  30. #壓縮的類型
  31. gzip_types text/plain application/x-javascript text/css application/xml;
  32. #讓前端的緩存服務器混村經(jīng)過的gzip壓縮的頁面
  33. gzip_vary on;
  34. # 配置轉發(fā)到8700 端口
  35. upstream huida{
  36. server 127.0.0.1:8700;
  37. }
  38. server {
  39. listen 80;
  40. listen 443 ssl; # 配置https,監(jiān)聽433端口
  41. server_name xxx.xxx; # 注意如果申請了域名配置再此,如果配置了證書才能https訪問
  42. error_page 405 =200 $request_uri;
  43. ssl_certificate cert/7629385.pem;
  44. ssl_certificate_key cert/7629385.key;
  45. client_max_body_size 50m;
  46. underscores_in_headers on;
  47. proxy_set_header Host $host;
  48. proxy_set_header X-Real-IP $remote_addr;
  49. proxy_set_header X-Real-IP $remote_addr;
  50. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  51. index index.htm index.html index.php;
  52. proxy_connect_timeout 60; #建立tcp協(xié)議的連接時間
  53. proxy_send_timeout 60; #發(fā)送接口的時間
  54. proxy_read_timeout 60; #讀取時間(接口響應時間)
  55. #charset koi8-r;
  56. #access_log logs/host.access.log main;
  57. # 配置轉發(fā)
  58. location /huida/ {
  59. add_header 'Access-Control-Allow-Origin' '*';
  60. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  61. add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Token';
  62. add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Token';
  63. proxy_pass http://huida;
  64. }
  65. location / {
  66. root /home/html/huida/;
  67. index index.html index.htm;
  68. }
  69. #靜態(tài)文件交給nginx處理 代理前端靜態(tài)資源
  70. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
  71. {
  72. root /home/html/huida/;
  73. expires 12;
  74. }
  75. #靜態(tài)文件交給nginx處理
  76. location ~ .*\.(js|css)?$
  77. {
  78. root /home/html/huida/;
  79. expires 15d;
  80. }
  81. #error_page 404 /404.html;
  82. # redirect server error pages to the static page /50x.html
  83. #
  84. error_page 500 502 503 504 /50x.html;
  85. location = /50x.html {
  86. root html;
  87. }
  88. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  89. #
  90. #location ~ \.php$ {
  91. # proxy_pass http://127.0.0.1;
  92. #}
  93. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  94. #
  95. #location ~ \.php$ {
  96. # root html;
  97. # fastcgi_pass 127.0.0.1:9000;
  98. # fastcgi_index index.php;
  99. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  100. # include fastcgi_params;
  101. #}
  102. # deny access to .htaccess files, if Apache's document root
  103. # concurs with nginx's one
  104. #
  105. #location ~ /\.ht {
  106. # deny all;
  107. #}
  108. }
  109. # another virtual host using mix of IP-, name-, and port-based configuration
  110. #
  111. #server {
  112. # listen 8000;
  113. # listen somename:8080;
  114. # server_name somename alias another.alias;
  115. # location / {
  116. # root html;
  117. # index index.html index.htm;
  118. # }
  119. #}
  120. # HTTPS server
  121. #
  122. #server {
  123. # listen 443 ssl;
  124. # server_name localhost;
  125. # ssl_certificate cert.pem;
  126. # ssl_certificate_key cert.key;
  127. # ssl_session_cache shared:SSL:1m;
  128. # ssl_session_timeout 5m;
  129. # ssl_ciphers HIGH:!aNULL:!MD5;
  130. # ssl_prefer_server_ciphers on;
  131. # location / {
  132. # root html;
  133. # index index.html index.htm;
  134. # }
  135. #}
  136. }

原文鏈接:https://blog.csdn.net/YMZ8848/article/details/123438614

本博文版權歸博主所有,轉載請注明地址!如有侵權、違法,請聯(lián)系admin@php.cn舉報處理!
全部評論 文明上網(wǎng)理性發(fā)言,請遵守新聞評論服務協(xié)議
0條評論
作者最新博文
關于我們 免責申明 意見反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓,幫助PHP學習者快速成長!
關注服務號 技術交流群
PHP中文網(wǎng)訂閱號
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時隨地碎片化學習
PHP中文網(wǎng)抖音號
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號

  • 登錄PHP中文網(wǎng),和優(yōu)秀的人一起學習!
    全站2000+教程免費學