某互联网企业技术发展史(四)配置nginx和mysql兼容Yii框架,上传网站并调试成功...
生活随笔
收集整理的這篇文章主要介紹了
某互联网企业技术发展史(四)配置nginx和mysql兼容Yii框架,上传网站并调试成功...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
昨天安裝好了php、nginx和squid,今天配置mysql和nginx,使nginx兼容Yii框架,并上傳網站,將網站調試和配置好。
1, 首先配置下php的時區# vi /etc/php.inidate.timezone = "Asia/Chongqing"# service php-fpm restart若沒有配置時區,php頁面可能會出現如下錯誤:date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead
2,配置mysql數據庫默認情況下mysql只有root用戶,并只可以本地登錄,昨天已經修改了root的密碼。我們將創建一個新用戶,并且為管理員級別,且可以遠程登錄,這樣我們就可以使用mysql administrator tool進行遠程管理,mysql遠程管理端口是3306,在下一步將配置防火墻允許3306端口。先用root登錄mysql,查詢賬號信息:# mysql -uroot -pEnter password: ******Welcome to the MySQL monitor.????Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.67 Source distribution
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
查詢賬號信息:mysql> select host, user,password from user;+--------------+------+-------------------------------------------+
| host???????????????? | user | password????????????????????????????????????????????????????????????????????|
+--------------+------+-------------------------------------------+
| localhost????????| root | *3DC3333qE11EEF04038E306BC8779D651 |
| 127.0.0.1????????| root |???????????????????????????????????????????????????????????????????????????????????? |
| localhost????????|????????????|???????????????????????????????????????????????????????????????????????????????????? |
+--------------+------+-------------------------------------------+
3 rows in set (0.00 sec)添加可遠程登錄的新管理員賬號:mysql> GRANT ALL PRIVILEGES ON *.* TO testroot@"%" IDENTIFIED BY 'password' WITH GRANT OPTION;Query OK, 0 rows affected (0.00 sec)查詢當前賬號信息:mysql> select host, user,password from user;+--------------+-------+-------------------------------------------+
| host???????????????? | user????| password????????????????????????????????????????????????????????????????????|
+--------------+-------+-------------------------------------------+
| localhost????????| root????| *3DC8AE44442111DE11EEF04038E306BC8779D651 |
| 127.0.0.1????????| root????|???????????????????????????????????????????????????????????????????????????????????? |
| localhost????????|???????????? |???????????????????????????????????????????????????????????????????????????????????? |
| % ? ? ? ? ? ? ? ? | testroot | *3DC8AE08411DE11EEF04038E306BC8779D651 |
+--------------+-------+-------------------------------------------+
4 rows in set (0.00 sec)刪除匿名賬戶:mysql> delete from user where user='';
3, 配置防火墻,允許遠程登錄mysql管理#?iptables -I INPUT -p tcp --dport 3306 -j ACCEPT或者# vim /etc/sysconfig/iptables-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT這樣,就可以使用mysql管理工具使用testroot賬號遠程登錄進行管理了。
4,導入網站數據庫,創建網站數據庫用戶使用mysql管理工具將數據庫備份還原到該服務器數據庫中;為網站創建普通賬號testweb,只允許本地登錄,賦予該賬號對網站數據庫的讀寫更新等權限。這樣網站就可以使用該賬號連接數據庫了。
5,上傳網站源代碼和Yii框架Yii框架位于網站根目錄下yii目錄:?/var/www/html/yii網站目錄位于根目錄下的testweb目錄下:/var/www/html/testweb配置網站數據庫信息。
5,配置nginx支持Yii框架由于網站使用了Yii框架,需要nginx實現rewrite的功能。nginx配置如下:/etc/nginx/nginx.confuser????nginx;
worker_processes????4;
error_log????/var/log/nginx/error.log warn;
pid????????????????/var/run/nginx.pid;
events {
????????worker_connections????50000;
}
http {
????????include???????????? /etc/nginx/mime.types;
????????default_type????application/octet-stream;
????????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????/var/log/nginx/access.log????main;
????????sendfile????????????????on;
????????#tcp_nopush???????? on;
????????keepalive_timeout????65;
????????gzip????on;
????????include /etc/nginx/conf.d/*.conf;
}
/etc/nginx/conf.d/default.confserver {
????????listen???????????? 8080;
????????server_name????localhost;
????????charset utf-8;
????????access_log????/var/log/nginx/log/host.access.log????main;
????????location / {
? ? ? ? ? ? ? ? root???? /var/www/html;
????????????????index????index.html index.htm default.htm default.html index.php default.php;
????????????????add_header Content-Type "text/html; charset=UTF-8";
????????????????add_header Content-Encoding "gzip";
????????}
????????????????# Disable logging for favicon
????????????????location = /favicon.ico {
????????????????????????????????log_not_found off;
????????????????????????????????access_log off;
????????????????}
????????????????# Disable logging for robots.txt
????????????????location = /robots.txt {
????????????????????????????????allow all;
????????????????????????????????log_not_found off;
????????????????????????????????access_log off;
????????????????}
????????????????# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
????????????????location ~ /\. {
????????????????????????????????deny all;
????????????????????????????????access_log off;
????????????????????????????????log_not_found off;
????????????????}
????????????????location ~* \.(jpg|jpeg|png|gif|css|js|swf|mp3|avi|flv|xml|zip|rar)$ {
????????????????????????????????expires 7d;
????????????????????????????????gzip on;
????????????????????????????????gzip_types????text/plain application/x-javascript text/css application/xml;
????????????????????????????????root /var/www/html;
????????????????}
????????????????location ~ /.svn/* {
????????????????????????????????deny all;
????????????????????????????????access_log off;
????????????????????????????????log_not_found off;
????????????????}
????????# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
????????#
????????location ~ \.php$ {
????????????????root???????????????????? /var/www/html;
????????????????fastcgi_pass???? 127.0.0.1:9000;
????????????????fastcgi_index????index.php;
????????????????fastcgi_param????SCRIPT_FILENAME????$document_root$fastcgi_script_name;
????????????????fastcgi_param????PATH_INFO $fastcgi_script_name;
????????????????include????????????????fastcgi_params;
????????}
????????????????# yii configuration
????????????????include conf.d/yii.common.conf.internal;
????????#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???? /usr/share/nginx/html;
????????}
}
/etc/nginx/conf.d/yii.common.conf.internal# BEGIN yiiframework.conf
# Block access to protected, framework, and nbproject (artifact from Netbeans)
location ~ /(yii|protected|framework|nbproject) {
????????deny all;
????????access_log off;
????????log_not_found off;
}
# Block access to theme-folder views directories
location ~ /themes/\w+/views {
????????deny all;
????????access_log off;
????????log_not_found off;
}
# Attempt the uri, uri+/, then fall back to yii's index.php with args included
# Note: old examples use IF statements, which nginx considers evil, this approach is more widely supported
location /testweb {
????????????????index index.php;
????????try_files $uri $uri/ /testweb/index.php?$args;
}
重啟nginx:# service nginx restartStopping nginx: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ ?OK ?]Starting nginx: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ ?OK ?]
瀏覽器中輸入網址:http://192.168.1.18/testweb/ 即可訪問到網站內容,請求首先經過squid,再轉發到nginx,然后經過php解析器。至此,網站初步配置基本完成,剩下調優和細化的工作了。
1, 首先配置下php的時區# vi /etc/php.inidate.timezone = "Asia/Chongqing"# service php-fpm restart若沒有配置時區,php頁面可能會出現如下錯誤:date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead
2,配置mysql數據庫默認情況下mysql只有root用戶,并只可以本地登錄,昨天已經修改了root的密碼。我們將創建一個新用戶,并且為管理員級別,且可以遠程登錄,這樣我們就可以使用mysql administrator tool進行遠程管理,mysql遠程管理端口是3306,在下一步將配置防火墻允許3306端口。先用root登錄mysql,查詢賬號信息:# mysql -uroot -pEnter password: ******Welcome to the MySQL monitor.????Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.67 Source distribution
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
查詢賬號信息:mysql> select host, user,password from user;+--------------+------+-------------------------------------------+
| host???????????????? | user | password????????????????????????????????????????????????????????????????????|
+--------------+------+-------------------------------------------+
| localhost????????| root | *3DC3333qE11EEF04038E306BC8779D651 |
| 127.0.0.1????????| root |???????????????????????????????????????????????????????????????????????????????????? |
| localhost????????|????????????|???????????????????????????????????????????????????????????????????????????????????? |
+--------------+------+-------------------------------------------+
3 rows in set (0.00 sec)添加可遠程登錄的新管理員賬號:mysql> GRANT ALL PRIVILEGES ON *.* TO testroot@"%" IDENTIFIED BY 'password' WITH GRANT OPTION;Query OK, 0 rows affected (0.00 sec)查詢當前賬號信息:mysql> select host, user,password from user;+--------------+-------+-------------------------------------------+
| host???????????????? | user????| password????????????????????????????????????????????????????????????????????|
+--------------+-------+-------------------------------------------+
| localhost????????| root????| *3DC8AE44442111DE11EEF04038E306BC8779D651 |
| 127.0.0.1????????| root????|???????????????????????????????????????????????????????????????????????????????????? |
| localhost????????|???????????? |???????????????????????????????????????????????????????????????????????????????????? |
| % ? ? ? ? ? ? ? ? | testroot | *3DC8AE08411DE11EEF04038E306BC8779D651 |
+--------------+-------+-------------------------------------------+
4 rows in set (0.00 sec)刪除匿名賬戶:mysql> delete from user where user='';
3, 配置防火墻,允許遠程登錄mysql管理#?iptables -I INPUT -p tcp --dport 3306 -j ACCEPT或者# vim /etc/sysconfig/iptables-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT這樣,就可以使用mysql管理工具使用testroot賬號遠程登錄進行管理了。
4,導入網站數據庫,創建網站數據庫用戶使用mysql管理工具將數據庫備份還原到該服務器數據庫中;為網站創建普通賬號testweb,只允許本地登錄,賦予該賬號對網站數據庫的讀寫更新等權限。這樣網站就可以使用該賬號連接數據庫了。
5,上傳網站源代碼和Yii框架Yii框架位于網站根目錄下yii目錄:?/var/www/html/yii網站目錄位于根目錄下的testweb目錄下:/var/www/html/testweb配置網站數據庫信息。
5,配置nginx支持Yii框架由于網站使用了Yii框架,需要nginx實現rewrite的功能。nginx配置如下:/etc/nginx/nginx.confuser????nginx;
worker_processes????4;
error_log????/var/log/nginx/error.log warn;
pid????????????????/var/run/nginx.pid;
events {
????????worker_connections????50000;
}
http {
????????include???????????? /etc/nginx/mime.types;
????????default_type????application/octet-stream;
????????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????/var/log/nginx/access.log????main;
????????sendfile????????????????on;
????????#tcp_nopush???????? on;
????????keepalive_timeout????65;
????????gzip????on;
????????include /etc/nginx/conf.d/*.conf;
}
/etc/nginx/conf.d/default.confserver {
????????listen???????????? 8080;
????????server_name????localhost;
????????charset utf-8;
????????access_log????/var/log/nginx/log/host.access.log????main;
????????location / {
? ? ? ? ? ? ? ? root???? /var/www/html;
????????????????index????index.html index.htm default.htm default.html index.php default.php;
????????????????add_header Content-Type "text/html; charset=UTF-8";
????????????????add_header Content-Encoding "gzip";
????????}
????????????????# Disable logging for favicon
????????????????location = /favicon.ico {
????????????????????????????????log_not_found off;
????????????????????????????????access_log off;
????????????????}
????????????????# Disable logging for robots.txt
????????????????location = /robots.txt {
????????????????????????????????allow all;
????????????????????????????????log_not_found off;
????????????????????????????????access_log off;
????????????????}
????????????????# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
????????????????location ~ /\. {
????????????????????????????????deny all;
????????????????????????????????access_log off;
????????????????????????????????log_not_found off;
????????????????}
????????????????location ~* \.(jpg|jpeg|png|gif|css|js|swf|mp3|avi|flv|xml|zip|rar)$ {
????????????????????????????????expires 7d;
????????????????????????????????gzip on;
????????????????????????????????gzip_types????text/plain application/x-javascript text/css application/xml;
????????????????????????????????root /var/www/html;
????????????????}
????????????????location ~ /.svn/* {
????????????????????????????????deny all;
????????????????????????????????access_log off;
????????????????????????????????log_not_found off;
????????????????}
????????# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
????????#
????????location ~ \.php$ {
????????????????root???????????????????? /var/www/html;
????????????????fastcgi_pass???? 127.0.0.1:9000;
????????????????fastcgi_index????index.php;
????????????????fastcgi_param????SCRIPT_FILENAME????$document_root$fastcgi_script_name;
????????????????fastcgi_param????PATH_INFO $fastcgi_script_name;
????????????????include????????????????fastcgi_params;
????????}
????????????????# yii configuration
????????????????include conf.d/yii.common.conf.internal;
????????#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???? /usr/share/nginx/html;
????????}
}
/etc/nginx/conf.d/yii.common.conf.internal# BEGIN yiiframework.conf
# Block access to protected, framework, and nbproject (artifact from Netbeans)
location ~ /(yii|protected|framework|nbproject) {
????????deny all;
????????access_log off;
????????log_not_found off;
}
# Block access to theme-folder views directories
location ~ /themes/\w+/views {
????????deny all;
????????access_log off;
????????log_not_found off;
}
# Attempt the uri, uri+/, then fall back to yii's index.php with args included
# Note: old examples use IF statements, which nginx considers evil, this approach is more widely supported
location /testweb {
????????????????index index.php;
????????try_files $uri $uri/ /testweb/index.php?$args;
}
重啟nginx:# service nginx restartStopping nginx: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ ?OK ?]Starting nginx: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ ?OK ?]
瀏覽器中輸入網址:http://192.168.1.18/testweb/ 即可訪問到網站內容,請求首先經過squid,再轉發到nginx,然后經過php解析器。至此,網站初步配置基本完成,剩下調優和細化的工作了。
轉載于:https://blog.51cto.com/babyhe/1166999
總結
以上是生活随笔為你收集整理的某互联网企业技术发展史(四)配置nginx和mysql兼容Yii框架,上传网站并调试成功...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安装vsftpd-3.0.2.tar.g
- 下一篇: Linux修改hostname(临时或者