Ubuntu+lnmp配置多站點方法

Ubuntu+lnmp配置多站點方法

//----------------------------------------------

首先我使用的阿里雲,阿里雲控制檯打開實例;有時候買了阿里的雲服務,控制檯實例顯示會慢半拍,稍等半小時即可;

在實例右邊的操作選項裏,選擇“更多”,選擇 安全組配置;

配置規則-入方向-添加安全組規則;打開界面;

端口範圍:80/80  (此處) 是打開80端口  ,如開通其他端口則填寫相應的端口號用斜槓隔開;

授權對象爲 0.0.0.0/0

注意:此處開放的端口,將用於後面的網站服務

//----------------------------------------------

安裝lnmp包:

由於我不需要過多的自定義,採取lnmp腳本安裝;

lnmp官網 , 下載最新lnmp,個人偏愛nginx,所用的是lnmp,用戶可以自行選擇要下載的包,可選 lnmp lamp,lnamp;

解壓:

tar -zvxf lnmp1.6-full.tar.gz   

進入解壓後的文件:

./install lnmp

 安裝過程選擇版本,數據庫管理員用戶和密碼(這個要記下來,後面用到) ,安裝時間約半小時到兩小時。

安裝期間需要保持聯網,如果遠程終端斷開,則導致安裝停止,此時再次登錄,reboot系統,再次運行install.sh安裝操作。

安裝完成後,進入   你的ip:80  可看到lnmp的頁面 ,探針和 phpmyadmin可以用起來了。這裏不贅述。

創建一個網絡用戶 ,會自動添加用戶組

adduser www

並輸入密碼

passwd www

//----------------------------------------------

這裏站點以 個人博客wordpress 爲例:

wordpress:

由於wordpress的特點,需要先行操作數據庫

mysql -u root -p 密碼

創建數據庫

create database wordpress;

權限配置

grant all on wordpress.* to wordpress@'localhost' identified by '密碼';
grant all on wordpress.* to wordpress@'%.%.%.%' identified by '密碼';
flush privileges;

下載wordpress包;

解壓:

unzip WordPress_27492.zip

創建 /var/www/ 目錄 將解壓的文件複製進入該目錄;故有

/var/www/wordpress/

由於wordpress自身特點 需要開放權限,

chmod -R 777 /var/www/wordpress/

此處也可以對該目錄 指定特定www用戶權限如

chmod -R www:www /var/www/wordpress/

然後開始配置nginx:

查看文件 /usr/local/nginx/conf/nginx.conf 如下

user  www www;

worker_processes auto;
worker_cpu_affinity auto;

error_log  /home/wwwlogs/nginx_error.log  crit;

pid        /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
    {
        use epoll;
        worker_connections 51200;
        multi_accept off;
        accept_mutex off;
    }

http
    {
        include       mime.types;
        default_type  application/octet-stream;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile on;
        sendfile_max_chunk 512k;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        #limit_conn_zone $binary_remote_addr zone=perip:10m;
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

        server_tokens off;
        access_log off;

server
    {
        listen 80 default_server reuseport;
        #listen [::]:80 default_server ipv6only=on;
        server_name 配置訪問的地址或域名(如果你有域名的話);
        index index.html index.htm index.php;
        root  /home/wwwroot/default;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }
include vhost/*.conf;
}

 

在最後幾行,如果是使用lnmp包安裝的,會出現

include vhost/*.conf;

此處是nginx多站點配置的重點,也是方便管理的重點。

/usr/local/nginx/conf/目錄下有一個vhost文件,在內部創建wordpress.conf

將/usr/local/nginx/conf/nginx.conf 內server部分填入wordpress.conf

然後進行 端口號 和 IP 的訪問,此處的端口號不能是ngnix.conf中已經監聽的端口號,否則會發生衝突

server
    {
        listen 配置wordpress訪問的端口號 default_server reuseport;
        #listen [::]:80 default_server ipv6only=on;
        server_name 配置訪問的IP地址或域名(如果你有域名的話);
        index index.html index.htm index.php;
        root  /var/www/html/wordpress;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }

然後重啓 lnmp

lnmp restart

如果顯示如下則成功

Stoping LNMP...
Stoping nginx...  done
[ ok ] Stopping mysql (via systemctl): mysql.service.
Gracefully shutting down php-fpm . done
Starting LNMP...
Starting nginx...  done
[ ok ] Starting mysql (via systemctl): mysql.service.
Starting php-fpm  done

此時從瀏覽器中打入

IP:port 即可查看配置的站點,此處我配置的是 80 和 911 端口

有 xxx.xxx.xxx.xxx:80   xxx.xxx.xxx.xxx:911 查看網頁

本人將wordpress 配置到了911上,則進入網頁能看到wordpress的安裝界面。

安裝過程會要求輸入數據庫密碼,由上面查得。

enjoy it !

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章