经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » PHP » 查看文章
ubuntu 编译安装NGINX
来源:cnblogs  作者:IT乐乐  时间:2021/1/25 11:22:57  对本文有异议

一、编译安装LNMP,并安装wordpress

1、下载nginx并解压缩。

  1. root@ubuntu:~# wget http://nginx.org/download/nginx-1.18.0.tar.gz
  2. root@ubuntu:~# tar -xf nginx-1.18.0.tar.gz

2、安装编译安装需要的依赖包。

  1. root@ubuntu:~# apt install -y gcc libgd-dev libgeoip-dev libpcre3 libpcre3-dev libssl-dev openssl

3、开始编译安装。

  1. root@ubuntu:~# cd nginx-1.18.0/
  2. root@ubuntu:~/nginx-1.18.0#
  3. root@ubuntu:~/nginx-1.18.0# ./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module
  4. --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module
  5. --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
  6. root@ubuntu:~/nginx-1.18.0# make -j 4
  7. root@ubuntu:~/nginx-1.18.0# make install

4、创建nginx用户和组,修改/apps/nginx目录所属用户和所属组。

  1. root@ubuntu:~/nginx-1.18.0# addgroup --gid 2000 nginx
  2. Adding group `nginx' (GID 2000) ...
  3. Done.
  4. root@ubuntu:~/nginx-1.18.0# useradd -m -r -s /bin/bash -u 2000 -g 2000 nginx
  5. root@ubuntu:~/nginx-1.18.0# chown nginx.nginx -R /apps/nginx/

5、修改nginx配置文件。

  1. root@ubuntu:~/nginx-1.18.0# vim /apps/nginx/conf/nginx.conf
  2. http {
  3. include mime.types;
  4. default_type application/octet-stream;
  5. sendfile on;
  6. keepalive_timeout 65;
  7. server {
  8. listen 80;
  9. server_name localhost;
  10. location / {
  11. root /apps/nginx/html;
  12. index index.html index.htm index.php;
  13. }
  14. location ~ \.php$ {
  15. root /apps/nginx/html;
  16. fastcgi_pass 127.0.0.1:9000;
  17. fastcgi_index index.php;
  18. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  19. include fastcgi_params;
  20. }
  21. error_page 500 502 503 504 /50x.html;
  22. location = /50x.html {
  23. root html;
  24. }

6、启动nginx。

  1. root@ubuntu:~/nginx-1.18.0# /apps/nginx/sbin/nginx
  2. root@ubuntu:/apps/nginx/html# echo nginx > /apps/nginx/html/index.html
  3. root@ubuntu:/apps/nginx/html# curl 10.0.0.135
  4. nginx

7、安装php-fpm。

  1. root@ubuntu:/apps/nginx/html# apt install php-fpm php-json php-mysqlnd

8、修改php配置文件。

  1. #修改下面开头的几行
  2. root@ubuntu:~# vim /etc/php/7.2/fpm/pool.d/www.conf
  3. user = nginx
  4. group = nginx
  5. listen =127.0.0.1:9000

9、安装mysql

  1. root@ubuntu1:/apps/nginx/html# apt install mysql-server

10、创建wordpress数据库账号、密码

  1. root@ubuntu:/apps/nginx/html# mysql
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 4
  4. Server version: 5.7.32-0ubuntu0.18.04.1 (Ubuntu)
  5. Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10. mysql> CREATE DATABASE wordpress;
  11. Query OK, 1 row affected (0.00 sec)
  12. mysql> GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"localhost" IDENTIFIED BY "123456";
  13. Query OK, 0 rows affected, 1 warning (0.00 sec)
  14. mysql> FLUSH PRIVILEGES;
  15. Query OK, 0 rows affected (0.00 sec)
  16. mysql> show databases;
  17. +--------------------+
  18. | Database |
  19. +--------------------+
  20. | information_schema |
  21. | mysql |
  22. | performance_schema |
  23. | sys |
  24. | wordpress |
  25. +--------------------+
  26. 5 rows in set (0.00 sec)

11、下载wordpress,解压缩,设置权限。

  1. root@ubuntu:/apps/nginx/html# tar -xf wordpress-5.6-zh_CN.tar.gz
  2. root@ubuntu:/apps/nginx/html# chown nginx.nginx -R /apps/nginx/html/wordpress

12、访问wordpress页面进行初始化。


二、配置虚拟主机,www.x.com域名实现首页访问,admin.x.com域名实现wordpress的后台访问。

1、本实验在上例的基础上完成。

2、修改windows的host文件,添加下面内容。

  1. 10.0.0.135 www.x.com
  2. 10.0.0.135 admin.x.com

3、修改nginx配置文件,添加下面虚拟主机,重启nginx服务。

  1. server {
  2. listen 80;
  3. server_name www.x.com;
  4. location / {
  5. root /apps/nginx/html/wordpress;
  6. index index.html index.php; }
  7. location ~ \.php$ {
  8. root /apps/nginx/html/wordpress;
  9. fastcgi_pass 127.0.0.1:9000;
  10. fastcgi_index index.php;
  11. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  12. include fastcgi_params;
  13. }
  14. }
  15. server {
  16. listen 80;
  17. server_name admin.x.com;
  18. location / {
  19. root /apps/nginx/html/wordpress/wp-admin;
  20. index index.html index.php; }
  21. location ~ \.php$ {
  22. root /apps/nginx/html/wordpress/wp-admin;
  23. fastcgi_pass 127.0.0.1:9000;
  24. fastcgi_index index.php;
  25. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  26. include fastcgi_params;
  27. }
  28. }
  29. root@ubuntu:~# /apps/nginx/sbin/nginx -s reload

4、使用域名访问wordpress。
成功访问后先登录管理后台 仪表盘——>设置——>常规——>WordPress地址(URL) 和 站点地址(URL)改为http://www.x.com,否则后续访问地址会变成ip地址。

原文链接:http://www.cnblogs.com/lele3721/p/14323855.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号