首页 > 技术文章 > nextcloud with nginx install on Archlinux

nicephil 2017-03-12 09:55 原文

nextcloud with nginx install on Archlinux

Modules Install

$ yaourt -S nginx-mainline php-fpm php-gd php-intl php-mcrypt php-apcu nextcloud mariadb syslog-ng

Modules Setup

SYSLOG

$ systemctl enable syslog-ng
$ systemctl restart syslog-ng

PHP

/etc/php/php.ini

date.timezone = Asia/Shanghai
display_errors=On
extension=gd.so
extension=iconv.so
extension=intl.so
extension=mcrypt.so
extension=mysqli.so
zend_extension=opcache.so
extension=pdo_mysql.so
extension=zip.so
[opcache]
opcache.enable=1
opcache.enable_cli=1

/etc/php/conf.d/apcu.ini

extension=apcu.so
[apc]
apc.enable=1
apc.shm_size=32M
apc.ttl=7200
apc.enable_cli=1

MariaDB

$ mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
$ systemctl enable mariadb
$ systemctl restart mariadb
$ mysql_secure_installation

Nginx

TLS/SSL

$ mkdir /etc/nginx/ssl
$ cd /etc/nginx/ssl
$ openssl req -new -x509 -nodes -newkey rsa:4096 $ -keyout server.key -out server.crt -days 1095
$ chmod 400 server.key
$ chmod 444 server.crt

PHP-FPM

/etc/php/php-fpm.d/www.conf

env[PATH] = /usr/local/bin:/usr/bin:/bin

$ systemctl enable php-fpm
$ systemctl restart php-fpm

NextCloud

Init DB

  1. $ mysql -u root -p 
  2. mysql> CREATE DATABASE `nextcloud` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; 
  3. mysql> CREATE USER `nextcloud`@'localhost' IDENTIFIED BY 'xxxxx'
  4. mysql> GRANT ALL PRIVILEGES ON `nextcloud`.* TO `nextcloud`@`localhost`; 
  5. mysql> \q 

Nginx

$ mkdir /etc/nginx/conf.d/
$ touch /etc/nginx/conf.d/nextcloud.conf

/etc/nginx/nginx.conf

  1. http { 
  2. include conf.d/*.conf 
  3. ... 

/etc/nginx/conf.d/nextcloud.conf

  1. upstream php-handler { 
  2. #server 127.0.0.1:9000; 
  3. server unix:/var/run/php-fpm/php-fpm.sock; 

  4.  
  5. #server { 
  6. # listen 80; 
  7. # server_name 45.63.49.131; 
  8. # # enforce https 
  9. # return 301 https://$server_name$request_uri; 
  10. #} 
  11.  
  12. server { 
  13. listen 8080
  14. listen 443 ssl http2; 
  15. ssl on; 
  16. server_name 45.63.49.131
  17.  
  18. ssl_certificate ssl/server.crt; 
  19. ssl_certificate_key ssl/server.key; 
  20.  
  21. # Add headers to serve security related headers 
  22. # Before enabling Strict-Transport-Security headers please read into this 
  23. # topic first. 
  24. add_header Strict-Transport-Security "max-age=15768000; 
  25. includeSubDomains; preload;"
  26. add_header X-Content-Type-Options nosniff; 
  27. add_header X-Frame-Options "SAMEORIGIN"
  28. add_header X-XSS-Protection "1; mode=block"
  29. add_header X-Robots-Tag none; 
  30. add_header X-Download-Options noopen; 
  31. add_header X-Permitted-Cross-Domain-Policies none; 
  32.  
  33. # Path to the root of your installation 
  34. root /usr/share/webapps/nextcloud/; 
  35.  
  36. location = /robots.txt { 
  37. allow all; 
  38. log_not_found off; 
  39. access_log off; 

  40.  
  41. # The following 2 rules are only needed for the user_webfinger app. 
  42. # Uncomment it if you're planning to use this app. 
  43. #rewrite ^/.well-known/host-meta /public.php?service=host-meta last; 
  44. #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json 
  45. # last; 
  46.  
  47. location = /.well-known/carddav { 
  48. return 301 $scheme://$host/remote.php/dav; 

  49. location = /.well-known/caldav { 
  50. return 301 $scheme://$host/remote.php/dav; 

  51.  
  52. # set max upload size 
  53. client_max_body_size 512M; 
  54. fastcgi_buffers 64 4K; 
  55.  
  56. # Disable gzip to avoid the removal of the ETag header 
  57. gzip off; 
  58.  
  59. # Uncomment if your server is build with the ngx_pagespeed module 
  60. # This module is currently not supported. 
  61. #pagespeed off; 
  62.  
  63. error_page 403 /core/templates/403.php; 
  64. error_page 404 /core/templates/404.php; 
  65.  
  66. location / { 
  67. rewrite ^ /index.php$uri

  68.  
  69. location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ { 
  70. deny all; 

  71. location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { 
  72. deny all; 

  73.  
  74. location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) { 
  75. fastcgi_split_path_info ^(.+\.php)(/.*)$; 
  76. include fastcgi_params; 
  77. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
  78. fastcgi_param PATH_INFO $fastcgi_path_info
  79. fastcgi_param HTTPS on; 
  80. #Avoid sending the security headers twice 
  81. fastcgi_param modHeadersAvailable true
  82. fastcgi_param front_controller_active true
  83. fastcgi_pass php-handler; 
  84. fastcgi_intercept_errors on; 
  85. fastcgi_request_buffering off; 

  86.  
  87. location ~ ^/(?:updater|ocs-provider)(?:$|/) { 
  88. try_files $uri/ =404
  89. index index.php; 

  90.  
  91. # Adding the cache control header for js and css files 
  92. # Make sure it is BELOW the PHP block 
  93. location ~* \.(?:css|js|woff|svg|gif)$ { 
  94. try_files $uri /index.php$uri$is_args$args
  95. add_header Cache-Control "public, max-age=7200"
  96. # Add headers to serve security related headers (It is intended to 
  97. # have those duplicated to the ones above) 
  98. # Before enabling Strict-Transport-Security headers please read into 
  99. # this topic first. 
  100. # add_header Strict-Transport-Security "max-age=15768000; 
  101. # includeSubDomains; preload;"; 
  102. add_header X-Content-Type-Options nosniff; 
  103. add_header X-Frame-Options "SAMEORIGIN"
  104. add_header X-XSS-Protection "1; mode=block"
  105. add_header X-Robots-Tag none; 
  106. add_header X-Download-Options noopen; 
  107. add_header X-Permitted-Cross-Domain-Policies none; 
  108. # Optional: Don't log access to assets 
  109. access_log off; 

  110.  
  111. location ~* \.(?:png|html|ttf|ico|jpg|jpeg)$ { 
  112. try_files $uri /index.php$uri$is_args$args
  113. # Optional: Don't log access to other assets 
  114. access_log off; 


Set ownership on /usr/share/webapps/nextcloud

$ sudo chown http:http -R /usr/share/webapps/nextcloud

Generate /etc/webapps/nextcloud/config/php.config

$ cd /usr/share/webapps/nextcloud
$ sudo -u http php occ maintenance:install --database
"mysql" --database-host “localhost:/var/run/mysqld/mysqld.sock” --database-name “nextcloud” --database-user “nextcloud” --database-pass
"xxxx" --admin-user “llwang” --admin-pass “xxxx”

Import server.crt in ‘opera or chrome’

  1. 选项-->高级设置-->管理证书-->导入 

$ opera “https://xxx.com:8080


nicephil@gmail.com

推荐阅读